<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Org ad hoc code, quick hacks and workarounds</title>
<!-- 2013-08-08 tor 11:56 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<meta name="generator" content="Org-mode"/>
<meta name="author" content="Worg people"/>
<style type="text/css">
 <!--/*--><![CDATA[/*><!--*/
  .title  { text-align: center; }
  .todo   { font-family: monospace; color: red; }
  .done   { color: green; }
  .tag    { background-color: #eee; font-family: monospace;
            padding: 2px; font-size: 80%; font-weight: normal; }
  .timestamp { color: #bebebe; }
  .timestamp-kwd { color: #5f9ea0; }
  .right  { margin-left: auto; margin-right: 0px;  text-align: right; }
  .left   { margin-left: 0px;  margin-right: auto; text-align: left; }
  .center { margin-left: auto; margin-right: auto; text-align: center; }
  .underline { text-decoration: underline; }
  #postamble p, #preamble p { font-size: 90%; margin: .2em; }
  p.verse { margin-left: 3%; }
  pre {
    border: 1px solid #ccc;
    box-shadow: 3px 3px 3px #eee;
    padding: 8pt;
    font-family: monospace;
    overflow: auto;
    margin: 1.2em;
  }
  pre.src {
    position: relative;
    overflow: visible;
    padding-top: 1.2em;
  }
  pre.src:before {
    display: none;
    position: absolute;
    background-color: white;
    top: -10px;
    right: 10px;
    padding: 3px;
    border: 1px solid black;
  }
  pre.src:hover:before { display: inline;}
  pre.src-sh:before    { content: 'sh'; }
  pre.src-bash:before  { content: 'sh'; }
  pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
  pre.src-R:before     { content: 'R'; }
  pre.src-perl:before  { content: 'Perl'; }
  pre.src-java:before  { content: 'Java'; }
  pre.src-sql:before   { content: 'SQL'; }

  table { border-collapse:collapse; }
  td, th { vertical-align:top;  }
  th.right  { text-align: center;  }
  th.left   { text-align: center;   }
  th.center { text-align: center; }
  td.right  { text-align: right;  }
  td.left   { text-align: left;   }
  td.center { text-align: center; }
  dt { font-weight: bold; }
  .footpara:nth-child(2) { display: inline; }
  .footpara { display: block; }
  .footdef  { margin-bottom: 1em; }
  .figure { padding: 1em; }
  .figure p { text-align: center; }
  .inlinetask {
    padding: 10px;
    border: 2px solid gray;
    margin: 10px;
    background: #ffffcc;
  }
  #org-div-home-and-up
   { text-align: right; font-size: 70%; white-space: nowrap; }
  textarea { overflow-x: auto; }
  .linenr { font-size: smaller }
  .code-highlighted { background-color: #ffff00; }
  .org-info-js_info-navigation { border-style: none; }
  #org-info-js_console-label
    { font-size: 10px; font-weight: bold; white-space: nowrap; }
  .org-info-js_search-highlight
    { background-color: #ffff00; color: #000000; font-weight: bold; }
  /*]]>*/-->
</style>
<link rel="stylesheet" type="text/css" href="http://thomasf.github.io/solarized-css/solarized-light.min.css" />
<script type="text/javascript">
/*
@licstart  The following is the entire license notice for the
JavaScript code in this tag.

Copyright (C) 2012  Free Software Foundation, Inc.

The JavaScript code in this tag is free software: you can
redistribute it and/or modify it under the terms of the GNU
General Public License (GNU GPL) as published by the Free Software
Foundation, either version 3 of the License, or (at your option)
any later version.  The code is distributed WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE.  See the GNU GPL for more details.

As additional permission under GNU GPL version 3 section 7, you
may distribute non-source (e.g., minimized or compacted) forms of
that code without the copy of the GNU GPL normally required by
section 4, provided you include this license notice and a URL
through which recipients can access the Corresponding Source.


@licend  The above is the entire license notice
for the JavaScript code in this tag.
*/
<!--/*--><![CDATA[/*><!--*/
 function CodeHighlightOn(elem, id)
 {
   var target = document.getElementById(id);
   if(null != target) {
     elem.cacheClassElem = elem.className;
     elem.cacheClassTarget = target.className;
     target.className = "code-highlighted";
     elem.className   = "code-highlighted";
   }
 }
 function CodeHighlightOff(elem, id)
 {
   var target = document.getElementById(id);
   if(elem.cacheClassElem)
     elem.className = elem.cacheClassElem;
   if(elem.cacheClassTarget)
     target.className = elem.cacheClassTarget;
 }
/*]]>*///-->
</script>
</head>
<body>
<div id="content">
<h1 class="title">Org ad hoc code, quick hacks and workarounds</h1>
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#sec-1">Hacking Org: Working within Org-mode.</a>
<ul>
<li><a href="#sec-1-1">Org Agenda</a>
<ul>
<li><a href="#sec-1-1-1">Picking up a random task in the global TODO list</a></li>
</ul>
</li>
<li><a href="#sec-1-2">Building and Managing Org</a>
<ul>
<li><a href="#compiling-org-without-make">Generating autoloads and Compiling Org without make</a></li>
<li><a href="#sec-1-2-2">Reload Org</a></li>
<li><a href="#check-old-link-escapes">Check for possibly problematic old link escapes</a></li>
</ul>
</li>
<li><a href="#sec-1-3">Structure Movement and Editing</a>
<ul>
<li><a href="#sec-1-3-1">Show next/prev heading tidily</a></li>
<li><a href="#sec-1-3-2">Promote all items in subtree</a></li>
<li><a href="#heading-to-link">Turn a heading into an Org link</a></li>
<li><a href="#sec-1-3-4">Using M-up and M-down to transpose paragraphs</a></li>
<li><a href="#sec-1-3-5">Changelog support for org headers</a></li>
<li><a href="#sec-1-3-6">Different org-cycle-level behavior</a></li>
<li><a href="#sec-1-3-7">Count words in an Org buffer</a></li>
<li><a href="#sec-1-3-8">Check for misplaced SCHEDULED and DEADLINE cookies</a></li>
<li><a href="#sec-1-3-9">Sorting list by checkbox type</a></li>
</ul>
</li>
<li><a href="#sec-1-4">Org Table</a>
<ul>
<li><a href="#sec-1-4-1">Align all tables in a file</a></li>
<li><a href="#transpose-table">Transpose table</a></li>
<li><a href="#sec-1-4-3">Manipulate hours/minutes/seconds in table formulas</a></li>
<li><a href="#sec-1-4-4">Dates computation</a></li>
<li><a href="#sec-1-4-5">Hex computation</a></li>
<li><a href="#field-coordinates-in-formulas">Field coordinates in formulas (<code>@#</code> and <code>$#</code>)</a></li>
<li><a href="#column-sequence-in-row">Change the column sequence in one row only</a></li>
</ul>
</li>
<li><a href="#sec-1-5">Capture and Remember</a>
<ul>
<li><a href="#sec-1-5-1">Customize the size of the frame for remember</a></li>
</ul>
</li>
<li><a href="#sec-1-6">Handling Links</a>
<ul>
<li><a href="#sec-1-6-1">Turn a heading into an org link</a></li>
<li><a href="#sec-1-6-2">Quickaccess to the link part of hyperlinks</a></li>
<li><a href="#sec-1-6-3">Insert link with HTML title as default description</a></li>
</ul>
</li>
<li><a href="#sec-1-7">Archiving Content in Org-Mode</a>
<ul>
<li><a href="#sec-1-7-1">Preserve top level headings when archiving to a file</a></li>
<li><a href="#sec-1-7-2">Archive in a date tree</a></li>
<li><a href="#sec-1-7-3">Add inherited tags to archived entries</a></li>
</ul>
</li>
<li><a href="#sec-1-8">Using and Managing Org-Metadata</a>
<ul>
<li><a href="#sec-1-8-1">Remove redundant tags of headlines</a></li>
<li><a href="#sec-1-8-2">Remove empty property drawers</a></li>
<li><a href="#sec-1-8-3">Group task list by a property</a></li>
<li><a href="#sec-1-8-4">A way to tag a task so that when clocking-out user is prompted to take a note.</a></li>
<li><a href="#sec-1-8-5">Dynamically adjust tag position</a></li>
<li><a href="#sec-1-8-6">Use an "attach" link type to open files without worrying about their location</a></li>
</ul>
</li>
<li><a href="#sec-1-9">Org Agenda and Task Management</a>
<ul>
<li><a href="#sec-1-9-1">Make it easier to set org-agenda-files from multiple directories</a></li>
<li><a href="#set-agenda-files-by-filetag">Restrict org-agenda-files by filetag</a></li>
<li><a href="#sec-1-9-3">Highlight the agenda line under cursor</a></li>
<li><a href="#sec-1-9-4">Split frame horizontally for agenda</a></li>
<li><a href="#sec-1-9-5">Automatically add an appointment when clocking in a task</a></li>
<li><a href="#sec-1-9-6">Using external programs for appointments reminders</a></li>
<li><a href="#sec-1-9-7">Remove from agenda time grid lines that are in an appointment</a></li>
<li><a href="#sec-1-9-8">Disable version control for Org mode agenda files</a></li>
<li><a href="#sec-1-9-9">Easy customization of TODO colors</a></li>
<li><a href="#sec-1-9-10">Add an effort estimate on the fly when clocking in</a></li>
<li><a href="#sec-1-9-11">Use idle timer for automatic agenda views</a></li>
<li><a href="#sec-1-9-12">Refresh the agenda view regularly</a></li>
<li><a href="#sec-1-9-13">Reschedule agenda items to today with a single command</a></li>
<li><a href="#sec-1-9-14">Mark subtree DONE along with all subheadings</a></li>
<li><a href="#mark-done-when-all-checkboxes-checked">Mark heading done when all checkboxes are checked.</a></li>
<li><a href="#links-to-agenda-views">Links to custom agenda views</a></li>
</ul>
</li>
<li><a href="#sec-1-10">Exporting org files</a>
<ul>
<li><a href="#sec-1-10-1">Export Org to Org and handle includes.</a></li>
<li><a href="#latex-command-for-floats">Specifying LaTeX commands to floating environments</a></li>
<li><a href="#sec-1-10-3">Styling code sections with CSS</a></li>
</ul>
</li>
<li><a href="#sec-1-11">Babel</a>
<ul>
<li><a href="#sec-1-11-1">How do I preview LaTeX fragments when in a LaTeX source block?</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#sec-2">Hacking Org: Working with Org-mode and other Emacs Packages.</a>
<ul>
<li><a href="#sec-2-1">org-remember-anything</a></li>
<li><a href="#sec-2-2">Org-mode and saveplace.el</a></li>
<li><a href="#sec-2-3">Using ido-mode for org-refile (and archiving via refile)</a></li>
<li><a href="#sec-2-4">Using ido-completing-read to find attachments</a></li>
<li><a href="#sec-2-5">Link to Gnus messages by Message-Id</a></li>
<li><a href="#sec-2-6">Store link to a message when sending in Gnus</a></li>
<li><a href="#sec-2-7">Send html messages and attachments with Wanderlust</a>
<ul>
<li><a href="#sec-2-7-1">Send HTML message</a></li>
<li><a href="#sec-2-7-2">Attach HTML of region or subtree</a></li>
<li><a href="#sec-2-7-3">Adopting for Gnus</a></li>
</ul>
</li>
<li><a href="#sec-2-8">Add sunrise/sunset times to the agenda.</a></li>
<li><a href="#sec-2-9">Add lunar phases to the agenda.</a></li>
</ul>
</li>
<li><a href="#sec-3">Lunar phase</a>
<ul>
<li><a href="#sec-3-1">Export BBDB contacts to org-contacts.el</a></li>
<li><a href="#sec-3-2">Calculating date differences - how to write a simple elisp function</a></li>
<li><a href="#sec-3-3">ibuffer and org files</a></li>
<li><a href="#sec-3-4">Enable org-mode links in other modes</a></li>
<li><a href="#sec-3-5">poporg.el: edit comments in org-mode</a></li>
<li><a href="#sec-3-6">Convert a .csv file to an Org-mode table</a></li>
</ul>
</li>
<li><a href="#sec-4">Hacking Org: Working with Org-mode and External Programs.</a>
<ul>
<li><a href="#sec-4-1">Use Org-mode with Screen [Andrew Hyatt]</a></li>
<li><a href="#org-agenda-appt-zenity">Org Agenda + Appt + Zenity</a></li>
<li><a href="#sec-4-3">Org and appointment notifications on Mac OS 10.8</a></li>
<li><a href="#sec-4-4">Org-Mode + gnome-osd</a></li>
<li><a href="#sec-4-5">txt2org convert text data to org-mode tables</a></li>
<li><a href="#sec-4-6">remind2org</a></li>
<li><a href="#sec-4-7">Useful webjumps for conkeror</a></li>
<li><a href="#sec-4-8">Use MathJax for HTML export without requiring JavaScript</a></li>
<li><a href="#sec-4-9">Search Org files using lgrep</a></li>
<li><a href="#sec-4-10">Automatic screenshot insertion</a></li>
<li><a href="#sec-4-11">Capture invitations/appointments from MS Exchange emails</a></li>
<li><a href="#sec-4-12">Audio/video file playback within org mode</a></li>
<li><a href="#sec-4-13">Under X11 Keep a window with the current agenda items at all time</a></li>
<li><a href="#sec-4-14">Script (thru procmail) to output emails to an Org file</a></li>
<li><a href="#fileconversion">Save File With Different Format for Headings (fileconversion)</a>
<ul>
<li><a href="#hidestarsfile">Headings Without Leading Stars (hidestarsfile and nbspstarsfile)</a></li>
<li><a href="#markdownstarsfile">Headings in Markdown Format (markdownstarsfile)</a></li>
<li><a href="#fileconversion-code">emacs-lisp code</a></li>
</ul>
</li>
<li><a href="#sec-4-16">Meaningful diff for org files in a git repository</a></li>
<li><a href="#sec-4-17">Opening devonthink links</a></li>
</ul>
</li>
<li><a href="#sec-5">Musings</a>
<ul>
<li><a href="#sec-5-1">Cooking?  Brewing?</a></li>
</ul>
</li>
</ul>
</div>
</div>
<p>
<a href="index.html">{Back to Worg's index}</a>
</p>

<p>
This page is for ad hoc bits of code. Feel free to add quick hacks and
workaround. Go crazy.
</p>

<div id="outline-container-sec-1" class="outline-2">
<h2 id="sec-1">Hacking Org: Working within Org-mode.</h2>
<div class="outline-text-2" id="text-1">
</div><div id="outline-container-sec-1-1" class="outline-3">
<h3 id="sec-1-1">Org Agenda</h3>
<div class="outline-text-3" id="text-1-1">
</div><div id="outline-container-sec-1-1-1" class="outline-4">
<h4 id="sec-1-1-1">Picking up a random task in the global TODO list</h4>
<div class="outline-text-4" id="text-1-1-1">
<p>
Tony day <a href="http://mid.gmane.org/m2zk19l1me.fsf%2540gmail.com">shared</a> <a href="https://gist.github.com/4343164">this gist</a> to pick up a
random task.
</p>
</div>
</div>
</div>
<div id="outline-container-sec-1-2" class="outline-3">
<h3 id="sec-1-2">Building and Managing Org</h3>
<div class="outline-text-3" id="text-1-2">
</div><div id="outline-container-compiling-org-without-make" class="outline-4">
<h4 id="compiling-org-without-make"><a id="sec-1-2-1" name="sec-1-2-1"></a>Generating autoloads and Compiling Org without make</h4>
<div class="outline-text-4" id="text-compiling-org-without-make">

<p>
Compilation is optional, but you <span class="underline">must</span> update the autoloads file
each time you update org, even when you run org uncompiled!
</p>

<p>
Starting with Org 7.9 you'll find functions for creating the
autoload files and do byte-compilation in <code>mk/org-fixup.el</code>.  When
you execute the commands below, your current directory must be where
org has been unpacked into, in other words the file <code>README</code> should
be found in your current directory and the directories <code>lisp</code> and
<code>etc</code> should be subdirectories of it.  The command <code>emacs</code> should be
found in your <code>PATH</code> and start the Emacs version you are using.  To
make just the autoloads file do:
</p>
<pre class="example">
emacs -batch -Q -L lisp -l ../mk/org-fixup -f org-make-autoloads
</pre>
<p>
To make the autoloads file and byte-compile org:
</p>
<pre class="example">
emacs -batch -Q -L lisp -l ../mk/org-fixup -f org-make-autoloads-compile
</pre>
<p>
To make the autoloads file and byte-compile all of org again:
</p>
<pre class="example">
emacs -batch -Q -L lisp -l ../mk/org-fixup -f org-make-autoloads-compile-force
</pre>
<p>
If you are not using Git, you'll have to make fake version strings
first if <code>org-version.el</code> is not already available (if it is, you
could also edit the version strings there).
</p>
<pre class="example">
emacs -batch -Q -L lisp -l ../mk/org-fixup \
--eval '(let ((org-fake-release "7.9.1")(org-fake-git-version "7.9.1-fake"))\
(org-make-autoloads))'
</pre>
<p>
The above assumes a
POSIX shell for its quoting.  Windows <code>CMD.exe</code> has quite different
quoting rules and this won't work, so your other option is to start
Emacs like this
</p>
<pre class="example">
emacs -Q -L lisp -l ../mk/org-fixup
</pre>
<p>
then paste the following into the <code>*scratch*</code> buffer
</p>
<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">let</span> ((org-fake-release     <span style="color: #2aa198;">"7.9.1"</span>)
      (org-fake-git-version <span style="color: #2aa198;">"7.9.1-fake"</span>))
  (org-make-autoloads))
</pre>
</div>
<p>
position the cursor after the closing paren and press <code>C-j</code> or <code>C-x
  C-e</code> to evaluate the form.  Of course you can replace
<code>org-make-autoloads</code> with <code>org-make-autoloads-compile</code> or even
<code>org-make-autoloads-compile-force</code> if you wish with both variants.
</p>

<p>
For <b>older org versions only</b> (that do not yet have
<code>mk/org-fixup.el</code>), you can use the definitions below.  To use
this function, adjust the variables <code>my/org-lisp-directory</code> and
<code>my/org-compile-sources</code> to suit your needs.  If you have
byte-compiled org, but want to run org uncompiled again, just remove
all <code>*.elc</code> files in the <code>lisp/</code> directory, set
<code>my/org-compile-sources</code> to <code>nil</code>.
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defvar</span> <span style="color: #268bd2;">my/org-lisp-directory</span> <span style="color: #2aa198;">"~/.emacs.d/org/lisp/"</span>
  <span style="color: #2aa198; font-style: italic;">"Directory where your org-mode files live."</span>)

(<span style="color: #859900;">defvar</span> <span style="color: #268bd2;">my/org-compile-sources</span> t
  <span style="color: #2aa198; font-style: italic;">"If `</span><span style="color: #2aa198; font-weight: bold; font-style: italic;">nil</span><span style="color: #2aa198; font-style: italic;">', never compile org-sources. `</span><span style="color: #2aa198; font-weight: bold; font-style: italic;">my/compile-org</span><span style="color: #2aa198; font-style: italic;">' will only create</span>
<span style="color: #2aa198; font-style: italic;">the autoloads file `</span><span style="color: #2aa198; font-weight: bold; font-style: italic;">org-loaddefs.el</span><span style="color: #2aa198; font-style: italic;">' then. If `t', compile the sources, too."</span>)

<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">Customize: (must end with a slash!)</span>
(setq my/org-lisp-directory <span style="color: #2aa198;">"~/.emacs.d/org/lisp/"</span>)

<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">Customize:</span>
(setq  my/org-compile-sources t)

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">my/compile-org</span>(<span style="color: #b58900;">&amp;optional</span> directory)
  <span style="color: #2aa198; font-style: italic;">"Generate autoloads file org-loaddefs.el.  Optionally compile</span>
<span style="color: #2aa198; font-style: italic;">   all *.el files that come with org-mode."</span>
  (interactive)
  (<span style="color: #859900;">defun</span> <span style="color: #268bd2;">my/compile-org</span>()
    <span style="color: #2aa198; font-style: italic;">"Generate autoloads file org-loaddefs.el.  Optionally compile</span>
<span style="color: #2aa198; font-style: italic;">     all *.el files that come with org-mode."</span>
    (interactive)
    (<span style="color: #859900;">let</span> ((dirlisp (file-name-directory my/org-lisp-directory)))
      (add-to-list 'load-path dirlisp)
      (<span style="color: #859900;">require</span> '<span style="color: #268bd2; font-weight: bold;">autoload</span>)
      (<span style="color: #859900;">let</span> ((generated-autoload-file (concat dirlisp <span style="color: #2aa198;">"org-loaddefs.el"</span>)))
        <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">create the org-loaddefs file</span>
        (update-directory-autoloads dirlisp)
        (<span style="color: #859900;">when</span> my/org-compile-sources
          <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">optionally byte-compile</span>
          (byte-recompile-directory dirlisp 0 'force)))))
</pre>
</div>
</div>
</div>

<div id="outline-container-sec-1-2-2" class="outline-4">
<h4 id="sec-1-2-2">Reload Org</h4>
<div class="outline-text-4" id="text-1-2-2">
<p>
As of Org version 6.23b (released Sunday Feb 22, 2009) there is a new
function to reload org files.
</p>

<p>
Normally you want to use the compiled files since they are faster.
If you update your org files you can easily reload them with
</p>

<pre class="example">
M-x org-reload
</pre>

<p>
If you run into a bug and want to generate a useful backtrace you can
reload the source files instead of the compiled files with
</p>

<pre class="example">
C-u M-x org-reload
</pre>

<p>
and turn on the "Enter Debugger On Error" option.  Redo the action
that generates the error and cut and paste the resulting backtrace.
To switch back to the compiled version just reload again with
</p>

<pre class="example">
M-x org-reload
</pre>
</div>
</div>
<div id="outline-container-check-old-link-escapes" class="outline-4">
<h4 id="check-old-link-escapes"><a id="sec-1-2-3" name="sec-1-2-3"></a>Check for possibly problematic old link escapes</h4>
<div class="outline-text-4" id="text-check-old-link-escapes">
<p>
Starting with version 7.5 Org uses <a href="http://en.wikipedia.org/wiki/Percent-encoding">percent escaping</a> more consistently
and with a modified algorithm to determine which characters to escape
and how.
</p>

<p>
As a side effect this modified behaviour might break existing links if
they contain a sequence of characters that look like a percent escape
(e.g. <code>[0-9A-Fa-f]{2}</code>) but are in fact not a percent escape.
</p>

<p>
The function below can be used to perform a preliminary check for such
links in an Org mode file.  It will run through all links in the file
and issue a warning if it finds a percent escape sequence which is not
in old Org's list of known percent escapes.
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">dmaus/org-check-percent-escapes</span> ()
  <span style="color: #2aa198; font-style: italic;">"*Check buffer for possibly problematic old link escapes."</span>
  (interactive)
  (<span style="color: #859900;">when</span> (eq major-mode 'org-mode)
    (<span style="color: #859900;">let</span> ((old-escapes '(<span style="color: #2aa198;">"%20"</span> <span style="color: #2aa198;">"%5B"</span> <span style="color: #2aa198;">"%5D"</span> <span style="color: #2aa198;">"%E0"</span> <span style="color: #2aa198;">"%E2"</span> <span style="color: #2aa198;">"%E7"</span> <span style="color: #2aa198;">"%E8"</span> <span style="color: #2aa198;">"%E9"</span>
                         <span style="color: #2aa198;">"%EA"</span> <span style="color: #2aa198;">"%EE"</span> <span style="color: #2aa198;">"%F4"</span> <span style="color: #2aa198;">"%F9"</span> <span style="color: #2aa198;">"%FB"</span> <span style="color: #2aa198;">"%3B"</span> <span style="color: #2aa198;">"%3D"</span> <span style="color: #2aa198;">"%2B"</span>)))
      (<span style="color: #859900;">unless</span> (boundp 'warning-suppress-types)
        (setq warning-suppress-types <span style="color: #b58900;">nil</span>))
      (widen)
      (show-all)
      (goto-char (point-min))
      (<span style="color: #859900;">while</span> (re-search-forward org-any-link-re <span style="color: #b58900;">nil</span> t)
        (<span style="color: #859900;">let</span> ((end (match-end 0)))
          (goto-char (match-beginning 0))
          (<span style="color: #859900;">while</span> (re-search-forward <span style="color: #2aa198;">"%[0-9a-zA-Z]\\{2\\}"</span> end t)
            (<span style="color: #859900;">let</span> ((escape (match-string-no-properties 0)))
              (<span style="color: #859900;">unless</span> (member (upcase escape) old-escapes)
                (<span style="color: #cb4b16; font-weight: bold; text-decoration: underline;">warn</span> <span style="color: #2aa198;">"Found unknown percent escape sequence %s at buffer %s, position %d"</span>
                      escape
                      (buffer-name)
                      (<span style="color: #b58900;">-</span> (point) 3)))))
          (goto-char end))))))
</pre>
</div>
</div>
</div>
</div>
<div id="outline-container-sec-1-3" class="outline-3">
<h3 id="sec-1-3">Structure Movement and Editing</h3>
<div class="outline-text-3" id="text-1-3">
</div><div id="outline-container-sec-1-3-1" class="outline-4">
<h4 id="sec-1-3-1">Show next/prev heading tidily</h4>
<div class="outline-text-4" id="text-1-3-1">
<ul class="org-ul">
<li>Dan Davison
These close the current heading and open the next/previous heading.
</li>
</ul>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">ded/org-show-next-heading-tidily</span> ()
  <span style="color: #2aa198; font-style: italic;">"Show next entry, keeping other entries closed."</span>
  (<span style="color: #859900;">if</span> (<span style="color: #859900;">save-excursion</span> (end-of-line) (outline-invisible-p))
      (<span style="color: #859900;">progn</span> (org-show-entry) (show-children))
    (outline-next-heading)
    (<span style="color: #859900;">unless</span> (<span style="color: #b58900;">and</span> (bolp) (org-on-heading-p))
      (org-up-heading-safe)
      (hide-subtree)
      (<span style="color: #cb4b16; font-weight: bold; text-decoration: underline;">error</span> <span style="color: #2aa198;">"Boundary reached"</span>))
    (org-overview)
    (org-reveal t)
    (org-show-entry)
    (show-children)))

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">ded/org-show-previous-heading-tidily</span> ()
  <span style="color: #2aa198; font-style: italic;">"Show previous entry, keeping other entries closed."</span>
  (<span style="color: #859900;">let</span> ((pos (point)))
    (outline-previous-heading)
    (<span style="color: #859900;">unless</span> (<span style="color: #b58900;">and</span> (<span style="color: #b58900;">&lt;</span> (point) pos) (bolp) (org-on-heading-p))
      (goto-char pos)
      (hide-subtree)
      (<span style="color: #cb4b16; font-weight: bold; text-decoration: underline;">error</span> <span style="color: #2aa198;">"Boundary reached"</span>))
    (org-overview)
    (org-reveal t)
    (org-show-entry)
    (show-children)))

(setq org-use-speed-commands t)
(add-to-list 'org-speed-commands-user
             '(<span style="color: #2aa198;">"n"</span> ded/org-show-next-heading-tidily))
(add-to-list 'org-speed-commands-user
             '(<span style="color: #2aa198;">"p"</span> ded/org-show-previous-heading-tidily))
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-1-3-2" class="outline-4">
<h4 id="sec-1-3-2">Promote all items in subtree</h4>
<div class="outline-text-4" id="text-1-3-2">
<ul class="org-ul">
<li>Matt Lundin
</li>
</ul>

<p>
This function will promote all items in a subtree. Since I use
subtrees primarily to organize projects, the function is somewhat
unimaginatively called my-org-un-project:
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">my-org-un-project</span> ()
  (interactive)
  (org-map-entries 'org-do-promote <span style="color: #2aa198;">"LEVEL&gt;1"</span> 'tree)
  (org-cycle t))
</pre>
</div>
</div>
</div>
<div id="outline-container-heading-to-link" class="outline-4">
<h4 id="heading-to-link"><a id="sec-1-3-3" name="sec-1-3-3"></a>Turn a heading into an Org link</h4>
<div class="outline-text-4" id="text-heading-to-link">
<p>
From David Maus:
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">dmj:turn-headline-into-org-mode-link</span> ()
  <span style="color: #2aa198; font-style: italic;">"Replace word at point by an Org mode link."</span>
  (interactive)
  (<span style="color: #859900;">when</span> (org-at-heading-p)
    (<span style="color: #859900;">let</span> ((hl-text (nth 4 (org-heading-components))))
      (<span style="color: #859900;">unless</span> (<span style="color: #b58900;">or</span> (null hl-text)
                  (org-string-match-p <span style="color: #2aa198;">"^[ \t]*:[</span><span style="color: #2aa198; font-weight: bold;">^</span><span style="color: #2aa198;">:]+:$"</span> hl-text))
        (beginning-of-line)
        (search-forward hl-text (point-at-eol))
        (replace-string
         hl-text
         (format <span style="color: #2aa198;">"[[file:%s.org][%s]]"</span>
                 (org-link-escape hl-text)
                 (org-link-escape hl-text '((?\] . <span style="color: #2aa198;">"%5D"</span>) (?\[ . <span style="color: #2aa198;">"%5B"</span>))))
         <span style="color: #b58900;">nil</span> (<span style="color: #b58900;">-</span> (point) (length hl-text)) (point))))))
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-1-3-4" class="outline-4">
<h4 id="sec-1-3-4">Using M-up and M-down to transpose paragraphs</h4>
<div class="outline-text-4" id="text-1-3-4">
<p>
From Paul Sexton: By default, if used within ordinary paragraphs in
org mode, <code>M-up</code> and <code>M-down</code> transpose <b>lines</b> (not sentences).  The
following code makes these keys transpose paragraphs, keeping the
point at the start of the moved paragraph. Behavior in tables and
headings is unaffected. It would be easy to modify this to transpose
sentences.
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">org-transpose-paragraphs</span> (arg)
 (interactive)
 (<span style="color: #859900;">when</span> (<span style="color: #b58900;">and</span> (<span style="color: #b58900;">not </span>(<span style="color: #b58900;">or</span> (org-at-table-p) (org-on-heading-p) (org-at-item-p)))
            (thing-at-point 'sentence))
   (transpose-paragraphs arg)
   (backward-paragraph)
   (re-search-forward <span style="color: #2aa198;">"[[:graph:]]"</span>)
   (goto-char (match-beginning 0))
   t))

(add-to-list 'org-metaup-hook 
 (<span style="color: #b58900;">lambda</span> () (interactive) (org-transpose-paragraphs -1)))
(add-to-list 'org-metadown-hook 
 (<span style="color: #b58900;">lambda</span> () (interactive) (org-transpose-paragraphs 1)))
</pre>
</div>
</div>
</div>

<div id="outline-container-sec-1-3-5" class="outline-4">
<h4 id="sec-1-3-5">Changelog support for org headers</h4>
<div class="outline-text-4" id="text-1-3-5">
<p>
&#x2013; James TD Smith
</p>

<p>
Put the following in your <code>.emacs</code>, and <code>C-x 4 a</code> and other functions which
use <code>add-log-current-defun</code> like <code>magit-add-log</code> will pick up the nearest org
headline as the "current function" if you add a changelog entry from an org
buffer.
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">org-log-current-defun</span> ()
  (<span style="color: #859900;">save-excursion</span>
    (org-back-to-heading)
    (<span style="color: #859900;">if</span> (looking-at org-complex-heading-regexp)
        (match-string 4))))

(add-hook 'org-mode-hook
          (<span style="color: #b58900;">lambda</span> ()
            (make-variable-buffer-local 'add-log-current-defun-function)
            (setq add-log-current-defun-function 'org-log-current-defun)))
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-1-3-6" class="outline-4">
<h4 id="sec-1-3-6">Different org-cycle-level behavior</h4>
<div class="outline-text-4" id="text-1-3-6">
<p>
&#x2013; Ryan Thompson
</p>

<p>
In recent org versions, when your point (cursor) is at the end of an
empty header line (like after you first created the header), the TAB
key (<code>org-cycle</code>) has a special behavior: it cycles the headline through
all possible levels. However, I did not like the way it determined
"all possible levels," so I rewrote the whole function, along with a
couple of supporting functions.
</p>

<p>
The original function's definition of "all possible levels" was "every
level from 1 to one more than the initial level of the current
headline before you started cycling." My new definition is "every
level from 1 to one more than the previous headline's level." So, if
you have a headline at level 4 and you use ALT+RET to make a new
headline below it, it will cycle between levels 1 and 5, inclusive.
</p>

<p>
The main advantage of my custom <code>org-cycle-level</code> function is that it
is stateless: the next level in the cycle is determined entirely by
the contents of the buffer, and not what command you executed last.
This makes it more predictable, I hope.
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">require</span> '<span style="color: #268bd2; font-weight: bold;">cl</span>)

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">org-point-at-end-of-empty-headline</span> ()
  <span style="color: #2aa198; font-style: italic;">"If point is at the end of an empty headline, return t, else nil."</span>
  (<span style="color: #b58900;">and</span> (looking-at <span style="color: #2aa198;">"[ \t]*$"</span>)
       (<span style="color: #859900;">save-excursion</span>
         (beginning-of-line 1)
         (looking-at (concat <span style="color: #2aa198;">"^</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">(</span><span style="color: #2aa198;">\\*+</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">)</span><span style="color: #2aa198;">[ \t]+</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">(</span><span style="color: #2aa198;">"</span> org-todo-regexp <span style="color: #2aa198;">"</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">)</span><span style="color: #2aa198;">?[ \t]*"</span>)))))

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">org-level-increment</span> ()
  <span style="color: #2aa198; font-style: italic;">"Return the number of stars that will be added or removed at a</span>
<span style="color: #2aa198; font-style: italic;">time to headlines when structure editing, based on the value of</span>
<span style="color: #2aa198; font-style: italic;">`</span><span style="color: #2aa198; font-weight: bold; font-style: italic;">org-odd-levels-only</span><span style="color: #2aa198; font-style: italic;">'."</span>
  (<span style="color: #859900;">if</span> org-odd-levels-only 2 1))

(<span style="color: #859900;">defvar</span> <span style="color: #268bd2;">org-previous-line-level-cached</span> <span style="color: #b58900;">nil</span>)

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">org-recalculate-previous-line-level</span> ()
  <span style="color: #2aa198; font-style: italic;">"Same as `</span><span style="color: #2aa198; font-weight: bold; font-style: italic;">org-get-previous-line-level</span><span style="color: #2aa198; font-style: italic;">', but does not use cached</span>
<span style="color: #2aa198; font-style: italic;">value. It does *set* the cached value, though."</span>
  (set 'org-previous-line-level-cached
       (<span style="color: #859900;">let</span> ((current-level (org-current-level))
             (prev-level (<span style="color: #859900;">when</span> (<span style="color: #b58900;">&gt;</span> (line-number-at-pos) 1)
                           (<span style="color: #859900;">save-excursion</span>
                             (previous-line)
                             (org-current-level)))))
         (<span style="color: #859900;">cond</span> ((null current-level) <span style="color: #b58900;">nil</span>) <span style="color: #93a1a1; font-style: italic;">; </span><span style="color: #93a1a1;">Before first headline</span>
               ((null prev-level) 0)      <span style="color: #93a1a1; font-style: italic;">; </span><span style="color: #93a1a1;">At first headline</span>
               (prev-level)))))

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">org-get-previous-line-level</span> ()
  <span style="color: #2aa198; font-style: italic;">"Return the outline depth of the last headline before the</span>
<span style="color: #2aa198; font-style: italic;">current line. Returns 0 for the first headline in the buffer, and</span>
<span style="color: #2aa198; font-style: italic;">nil if before the first headline."</span>
  <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">This calculation is quite expensive, with all the regex searching</span>
  <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">and stuff. Since org-cycle-level won't change lines, we can reuse</span>
  <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">the last value of this command.</span>
  (<span style="color: #b58900;">or</span> (<span style="color: #b58900;">and</span> (eq last-command 'org-cycle-level)
           org-previous-line-level-cached)
      (org-recalculate-previous-line-level)))

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">org-cycle-level</span> ()
  (interactive)
  (<span style="color: #859900;">let</span> ((org-adapt-indentation <span style="color: #b58900;">nil</span>))
    (<span style="color: #859900;">when</span> (org-point-at-end-of-empty-headline)
      (setq this-command 'org-cycle-level) <span style="color: #93a1a1; font-style: italic;">;</span><span style="color: #93a1a1;">Only needed for caching</span>
      (<span style="color: #859900;">let</span> ((cur-level (org-current-level))
            (prev-level (org-get-previous-line-level)))
        (<span style="color: #859900;">cond</span>
         <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">If first headline in file, promote to top-level.</span>
         ((= prev-level 0)
          (<span style="color: #859900;">loop</span> repeat (/ (<span style="color: #b58900;">-</span> cur-level 1) (org-level-increment))
                do (org-do-promote)))
         <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">If same level as prev, demote one.</span>
         ((= prev-level cur-level)
          (org-do-demote))
         <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">If parent is top-level, promote to top level if not already.</span>
         ((= prev-level 1)
          (<span style="color: #859900;">loop</span> repeat (/ (<span style="color: #b58900;">-</span> cur-level 1) (org-level-increment))
                do (org-do-promote)))
         <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">If top-level, return to prev-level.</span>
         ((= cur-level 1)
          (<span style="color: #859900;">loop</span> repeat (/ (<span style="color: #b58900;">-</span> prev-level 1) (org-level-increment))
                do (org-do-demote)))
         <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">If less than prev-level, promote one.</span>
         ((<span style="color: #b58900;">&lt;</span> cur-level prev-level)
          (org-do-promote))
         <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">If deeper than prev-level, promote until higher than</span>
         <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">prev-level.</span>
         ((<span style="color: #b58900;">&gt;</span> cur-level prev-level)
          (<span style="color: #859900;">loop</span> repeat (<span style="color: #b58900;">+</span> 1 (/ (<span style="color: #b58900;">-</span> cur-level prev-level) (org-level-increment)))
                do (org-do-promote))))
        t))))
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-1-3-7" class="outline-4">
<h4 id="sec-1-3-7">Count words in an Org buffer</h4>
<div class="outline-text-4" id="text-1-3-7">
<p>
#FIXME: Does not fit too well under Structure. Any idea where to put it?
Paul Sexton <a href="http://article.gmane.org/gmane.emacs.orgmode/38014">posted</a> this function to count words in an Org buffer:
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">org-word-count</span> (beg end
                           <span style="color: #b58900;">&amp;optional</span> count-latex-macro-args?
                           count-footnotes?)
  <span style="color: #2aa198; font-style: italic;">"Report the number of words in the Org mode buffer or selected region.</span>
<span style="color: #2aa198; font-style: italic;">Ignores:</span>
<span style="color: #2aa198; font-style: italic;">- comments</span>
<span style="color: #2aa198; font-style: italic;">- tables</span>
<span style="color: #2aa198; font-style: italic;">- source code blocks (#+BEGIN_SRC ... #+END_SRC, and inline blocks)</span>
<span style="color: #2aa198; font-style: italic;">- hyperlinks (but does count words in hyperlink descriptions)</span>
<span style="color: #2aa198; font-style: italic;">- tags, priorities, and </span><span style="color: #cb4b16; background-color: #fdf6e3; font-style: italic;">TODO</span><span style="color: #2aa198; font-style: italic;"> keywords in headers</span>
<span style="color: #2aa198; font-style: italic;">- sections tagged as 'not for export'.</span>

<span style="color: #2aa198; font-style: italic;">The text of footnote definitions is ignored, unless the optional argument</span>
<span style="color: #2aa198; font-style: italic;">COUNT-FOOTNOTES? is non-nil.</span>

<span style="color: #2aa198; font-style: italic;">If the optional argument COUNT-LATEX-MACRO-ARGS? is non-nil, the word count</span>
<span style="color: #2aa198; font-style: italic;">includes LaTeX macro arguments (the material between {curly braces}).</span>
<span style="color: #2aa198; font-style: italic;">Otherwise, and by default, every LaTeX macro counts as 1 word regardless</span>
<span style="color: #2aa198; font-style: italic;">of its arguments."</span>
  (interactive <span style="color: #2aa198;">"r"</span>)
  (<span style="color: #859900;">unless</span> mark-active
    (setf beg (point-min)
      end (point-max)))
  (<span style="color: #859900;">let</span> ((wc 0)
    (latex-macro-regexp <span style="color: #2aa198;">"\\\\[</span><span style="color: #2aa198; font-weight: bold;">A-Za-z</span><span style="color: #2aa198;">]+</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">(</span><span style="color: #2aa198;">\\[[</span><span style="color: #2aa198; font-weight: bold;">^</span><span style="color: #2aa198;">]]*\\]</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">|</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">)</span><span style="color: #2aa198;">{</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">(</span><span style="color: #2aa198;">[</span><span style="color: #2aa198; font-weight: bold;">^</span><span style="color: #2aa198;">}]*</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">)</span><span style="color: #2aa198;">}"</span>))
    (<span style="color: #859900;">save-excursion</span>
      (goto-char beg)
      (<span style="color: #859900;">while</span> (<span style="color: #b58900;">&lt;</span> (point) end)
        (<span style="color: #859900;">cond</span>
         <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">Ignore comments.</span>
         ((<span style="color: #b58900;">or</span> (org-in-commented-line) (org-at-table-p))
          <span style="color: #b58900;">nil</span>)
         <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">Ignore hyperlinks. But if link has a description, count</span>
         <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">the words within the description.</span>
         ((looking-at org-bracket-link-analytic-regexp)
          (<span style="color: #859900;">when</span> (match-string-no-properties 5)
            (<span style="color: #859900;">let</span> ((desc (match-string-no-properties 5)))
              (<span style="color: #859900;">save-match-data</span>
                (incf wc (length (remove <span style="color: #2aa198;">""</span> (org-split-string
                                             desc <span style="color: #2aa198;">"\\W"</span>)))))))
          (goto-char (match-end 0)))
         ((looking-at org-any-link-re)
          (goto-char (match-end 0)))
         <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">Ignore source code blocks.</span>
         ((org-in-regexps-block-p <span style="color: #2aa198;">"^#\\+BEGIN_SRC\\W"</span> <span style="color: #2aa198;">"^#\\+END_SRC\\W"</span>)
          <span style="color: #b58900;">nil</span>)
         <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">Ignore inline source blocks, counting them as 1 word.</span>
         ((<span style="color: #859900;">save-excursion</span>
            (backward-char)
            (looking-at org-babel-inline-src-block-regexp))
          (goto-char (match-end 0))
          (setf wc (<span style="color: #b58900;">+</span> 2 wc)))
         <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">Count latex macros as 1 word, ignoring their arguments.</span>
         ((<span style="color: #859900;">save-excursion</span>
            (backward-char)
            (looking-at latex-macro-regexp))
          (goto-char (<span style="color: #859900;">if</span> count-latex-macro-args?
                         (match-beginning 2)
                       (match-end 0)))
          (setf wc (<span style="color: #b58900;">+</span> 2 wc)))
         <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">Ignore footnotes.</span>
         ((<span style="color: #b58900;">and</span> (<span style="color: #b58900;">not </span>count-footnotes?)
               (<span style="color: #b58900;">or</span> (org-footnote-at-definition-p)
                   (org-footnote-at-reference-p)))
          <span style="color: #b58900;">nil</span>)
         (t
          (<span style="color: #859900;">let</span> ((contexts (org-context)))
            (<span style="color: #859900;">cond</span>
             <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">Ignore tags and </span><span style="color: #cb4b16; background-color: #fdf6e3; font-style: italic;">TODO</span><span style="color: #93a1a1;"> keywords, etc.</span>
             ((<span style="color: #b58900;">or</span> (assoc <span style="color: #657b83; font-style: italic;">:todo-keyword</span> contexts)
                  (assoc <span style="color: #657b83; font-style: italic;">:priority</span> contexts)
                  (assoc <span style="color: #657b83; font-style: italic;">:keyword</span> contexts)
                  (assoc <span style="color: #657b83; font-style: italic;">:checkbox</span> contexts))
              <span style="color: #b58900;">nil</span>)
             <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">Ignore sections marked with tags that are</span>
             <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">excluded from export.</span>
             ((assoc <span style="color: #657b83; font-style: italic;">:tags</span> contexts)
              (<span style="color: #859900;">if</span> (intersection (org-get-tags-at) org-export-exclude-tags
                                <span style="color: #657b83; font-style: italic;">:test</span> 'equal)
                  (org-forward-same-level 1)
                <span style="color: #b58900;">nil</span>))
             (t
              (incf wc))))))
        (re-search-forward <span style="color: #2aa198;">"\\w+\\W*"</span>)))
    (message (format <span style="color: #2aa198;">"%d words in %s."</span> wc
                     (<span style="color: #859900;">if</span> mark-active <span style="color: #2aa198;">"region"</span> <span style="color: #2aa198;">"buffer"</span>)))))
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-1-3-8" class="outline-4">
<h4 id="sec-1-3-8">Check for misplaced SCHEDULED and DEADLINE cookies</h4>
<div class="outline-text-4" id="text-1-3-8">
<p>
The <code>SCHEDULED</code> and <code>DEADLINE</code> cookies should be used on the line <b>right
below</b> the headline &#x2013; like this:
</p>

<div class="org-src-container">

<pre class="src src-org"><span style="color: #cb4b16;">* A headline</span>
,  <span style="color: #93a1a1; font-size: 90%; font-style: italic;">SCHEDULED:</span> <span style="color: #268bd2; text-decoration: underline;">&lt;2012-04-09 lun.&gt;</span>
</pre>
</div>

<p>
This is what <code>org-scheduled</code> and <code>org-deadline</code> (and other similar
commands) do.  And the manual explicitely tell people to stick to this
format (see the section "8.3.1 Inserting deadlines or schedules").
</p>

<p>
If you think you might have subtrees with misplaced <code>SCHEDULED</code> and
<code>DEADLINE</code> cookies, this command lets you check the current buffer:
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">org-check-misformatted-subtree</span> ()
  <span style="color: #2aa198; font-style: italic;">"Check misformatted entries in the current buffer."</span>
  (interactive)
  (show-all)
  (org-map-entries
   (<span style="color: #b58900;">lambda</span> ()
     (<span style="color: #859900;">when</span> (<span style="color: #b58900;">and</span> (move-beginning-of-line 2)
        (<span style="color: #b58900;">not </span>(looking-at org-heading-regexp)))
       (<span style="color: #859900;">if</span> (<span style="color: #b58900;">or</span> (<span style="color: #b58900;">and</span> (org-get-scheduled-time (point))
            (<span style="color: #b58900;">not </span>(looking-at (concat <span style="color: #2aa198;">"^.*"</span> org-scheduled-regexp))))
           (<span style="color: #b58900;">and</span> (org-get-deadline-time (point))
            (<span style="color: #b58900;">not </span>(looking-at (concat <span style="color: #2aa198;">"^.*"</span> org-deadline-regexp)))))
       (<span style="color: #859900;">when</span> (y-or-n-p <span style="color: #2aa198;">"Fix this subtree? "</span>)
         (message <span style="color: #2aa198;">"Call the function again when you're done fixing this subtree."</span>)
         (recursive-edit))
     (message <span style="color: #2aa198;">"All subtrees checked."</span>))))))
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-1-3-9" class="outline-4">
<h4 id="sec-1-3-9">Sorting list by checkbox type</h4>
<div class="outline-text-4" id="text-1-3-9">
<p>
You can use a custom function to sort list by checkbox type.
Here is a function suggested by Carsten:
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">org-sort-list-by-checkbox-type</span> ()
  <span style="color: #2aa198; font-style: italic;">"Sort list items according to Checkbox state."</span>
  (interactive)
  (org-sort-list
   <span style="color: #b58900;">nil</span> ?f
   (<span style="color: #b58900;">lambda</span> ()
     (<span style="color: #859900;">if</span> (looking-at org-list-full-item-re)
     (cdr (assoc (match-string 3)
             '((<span style="color: #2aa198;">"[X]"</span> . 1) (<span style="color: #2aa198;">"[-]"</span> . 2) (<span style="color: #2aa198;">"[ ]"</span> . 3) (<span style="color: #b58900;">nil</span> . 4))))
       4))))
</pre>
</div>

<p>
Use the function above directly on the list.  If you want to use an
equivalent function after <code>C-c ^ f</code>, use this one instead:
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">org-sort-list-by-checkbox-type-1</span> ()
  (<span style="color: #b58900;">lambda</span> ()
    (<span style="color: #859900;">if</span> (looking-at org-list-full-item-re)
        (cdr (assoc (match-string 3)
                    '((<span style="color: #2aa198;">"[X]"</span> . 1) (<span style="color: #2aa198;">"[-]"</span> . 2) (<span style="color: #2aa198;">"[ ]"</span> . 3) (<span style="color: #b58900;">nil</span> . 4))))
      4)))
</pre>
</div>
</div>
</div>
</div>
<div id="outline-container-sec-1-4" class="outline-3">
<h3 id="sec-1-4">Org Table</h3>
<div class="outline-text-3" id="text-1-4">
</div><div id="outline-container-sec-1-4-1" class="outline-4">
<h4 id="sec-1-4-1">Align all tables in a file</h4>
<div class="outline-text-4" id="text-1-4-1">
<p>
Andrew Young provided this function in <a href="http://thread.gmane.org/gmane.emacs.orgmode/58974/focus%3D58976">this thread</a>:
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">my-align-all-tables</span> ()
  (interactive)
  (org-table-map-tables 'org-table-align 'quietly))
</pre>
</div>
</div>
</div>
<div id="outline-container-transpose-table" class="outline-4">
<h4 id="transpose-table"><a id="sec-1-4-2" name="sec-1-4-2"></a>Transpose table</h4>
<div class="outline-text-4" id="text-transpose-table">

<p>
Since Org 7.8, you can use <code>org-table-transpose-table-at-point</code> (which
see.)  There are also other solutions:
</p>

<ul class="org-ul">
<li>with org-babel and Emacs Lisp: provided by Thomas S. Dye in the mailing
list, see <a href="http://thread.gmane.org/gmane.emacs.orgmode/23809/focus=23815">gmane</a> or <a href="http://lists.gnu.org/archive/html/emacs-orgmode/2010-04/msg00239.html">gnu</a>
</li>

<li>with org-babel and R: provided by Dan Davison in the mailing list (old
  <code>#+TBLR:</code> syntax), see <a href="http://thread.gmane.org/gmane.emacs.orgmode/10159/focus=10159">gmane</a> or <a href="http://lists.gnu.org/archive/html/emacs-orgmode/2008-12/msg00454.html">gnu</a>
</li>

<li>with field coordinates in formulas (<code>@#</code> and <code>$#</code>): see <a href="org-hacks.html#field-coordinates-in-formulas-transpose-table">Worg</a>.
</li>
</ul>
</div>
</div>
<div id="outline-container-sec-1-4-3" class="outline-4">
<h4 id="sec-1-4-3">Manipulate hours/minutes/seconds in table formulas</h4>
<div class="outline-text-4" id="text-1-4-3">
<p>
Both Bastien and Martin Halder have posted code (<a href="http://article.gmane.org/gmane.emacs.orgmode/39519">Bastien's code</a> and
<a href="http://article.gmane.org/gmane.emacs.orgmode/39519">Martin's code</a>) for interpreting <code>dd:dd</code> or <code>dd:dd:dd</code> strings (where
"<code>d</code>" is any digit) as time values in Org-mode table formula.  These
functions have now been wrapped up into a <code>with-time</code> macro which can
be used in table formula to translate table cell values to and from
numerical values for algebraic manipulation.
</p>

<p>
Here is the code implementing this macro.
</p>
<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">org-time-string-to-seconds</span> (s)
  <span style="color: #2aa198; font-style: italic;">"Convert a string HH:MM:SS to a number of seconds."</span>
  (<span style="color: #859900;">cond</span>
   ((<span style="color: #b58900;">and</span> (stringp s)
         (string-match <span style="color: #2aa198;">"</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">(</span><span style="color: #2aa198;">[0-9]+</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">)</span><span style="color: #2aa198;">:</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">(</span><span style="color: #2aa198;">[0-9]+</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">)</span><span style="color: #2aa198;">:</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">(</span><span style="color: #2aa198;">[0-9]+</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">)</span><span style="color: #2aa198;">"</span> s))
    (<span style="color: #859900;">let</span> ((hour (string-to-number (match-string 1 s)))
          (min (string-to-number (match-string 2 s)))
          (sec (string-to-number (match-string 3 s))))
      (<span style="color: #b58900;">+</span> (* hour 3600) (* min 60) sec)))
   ((<span style="color: #b58900;">and</span> (stringp s)
         (string-match <span style="color: #2aa198;">"</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">(</span><span style="color: #2aa198;">[0-9]+</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">)</span><span style="color: #2aa198;">:</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">(</span><span style="color: #2aa198;">[0-9]+</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">)</span><span style="color: #2aa198;">"</span> s))
    (<span style="color: #859900;">let</span> ((min (string-to-number (match-string 1 s)))
          (sec (string-to-number (match-string 2 s))))
      (<span style="color: #b58900;">+</span> (* min 60) sec)))
   ((stringp s) (string-to-number s))
   (t s)))

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">org-time-seconds-to-string</span> (secs)
  <span style="color: #2aa198; font-style: italic;">"Convert a number of seconds to a time string."</span>
  (<span style="color: #859900;">cond</span> ((<span style="color: #b58900;">&gt;=</span> secs 3600) (format-seconds <span style="color: #2aa198;">"%h:%.2m:%.2s"</span> secs))
        ((<span style="color: #b58900;">&gt;=</span> secs 60) (format-seconds <span style="color: #2aa198;">"%m:%.2s"</span> secs))
        (t (format-seconds <span style="color: #2aa198;">"%s"</span> secs))))

(<span style="color: #859900;">defmacro</span> <span style="color: #268bd2;">with-time</span> (time-output-p <span style="color: #b58900;">&amp;rest</span> exprs)
  <span style="color: #2aa198; font-style: italic;">"Evaluate an org-table formula, converting all fields that look</span>
<span style="color: #2aa198; font-style: italic;">like time data to integer seconds.  If TIME-OUTPUT-P then return</span>
<span style="color: #2aa198; font-style: italic;">the result as a time value."</span>
  (list
   (<span style="color: #859900;">if</span> time-output-p 'org-time-seconds-to-string 'identity)
   (cons 'progn
         (mapcar
          (<span style="color: #b58900;">lambda</span> (expr)
            `,(cons (car expr)
                    (mapcar
                     (<span style="color: #b58900;">lambda</span> (el)
                       (<span style="color: #859900;">if</span> (listp el)
                           (list 'with-time <span style="color: #b58900;">nil</span> el)
                         (org-time-string-to-seconds el)))
                     (cdr expr))))
          `,@exprs))))
</pre>
</div>

<p>
Which allows the following forms of table manipulation such as adding
and subtracting time values.
</p>
<pre class="example">
| Date             | Start | Lunch |  Back |   End |  Sum |
|------------------+-------+-------+-------+-------+------|
| [2011-03-01 Tue] |  8:00 | 12:00 | 12:30 | 18:15 | 9:45 |
#+TBLFM: $6='(with-time t (+ (- $5 $4) (- $3 $2)))
</pre>

<p>
and dividing time values by integers
</p>
<pre class="example">
|  time | miles | minutes/mile |
|-------+-------+--------------|
| 34:43 |   2.9 |        11:58 |
| 32:15 |  2.77 |        11:38 |
| 33:56 |   3.0 |        11:18 |
| 52:22 |  4.62 |        11:20 |
#+TBLFM: $3='(with-time t (/ $1 $2))
</pre>

<p>
<b>Update</b>: As of Org version 7.6, you can use the <code>T</code> flag (both in Calc and
Elisp formulas) to compute time durations.  For example:
</p>

<pre class="example">
| Task 1 | Task 2 |   Total |
|--------+--------+---------|
|  35:00 |  35:00 | 1:10:00 |
#+TBLFM: @2$3=$1+$2;T
</pre>
</div>
</div>
<div id="outline-container-sec-1-4-4" class="outline-4">
<h4 id="sec-1-4-4">Dates computation</h4>
<div class="outline-text-4" id="text-1-4-4">
<p>
Xin Shi <a href="http://article.gmane.org/gmane.emacs.orgmode/15692">asked</a> for a way to calculate the duration of 
dates stored in an org table.
</p>

<p>
Nick Dokos <a href="http://article.gmane.org/gmane.emacs.orgmode/15694">suggested</a>:
</p>

<p>
Try the following:
</p>

<pre class="example">
| Start Date |   End Date | Duration |
|------------+------------+----------|
| 2004.08.07 | 2005.07.08 |      335 |
#+TBLFM: $3=(date(&lt;$2&gt;)-date(&lt;$1&gt;))
</pre>

<p>
See <a href="http://thread.gmane.org/gmane.emacs.orgmode/7741">this thread</a> as well as <a href="http://article.gmane.org/gmane.emacs.orgmode/7753">this post</a> (which is really a followup on the
above).  The problem that this last article pointed out was solved in <a href="http://article.gmane.org/gmane.emacs.orgmode/8001">this
post</a> and Chris Randle's original musings are <a href="http://article.gmane.org/gmane.emacs.orgmode/6536/">here</a>.
</p>
</div>
</div>
<div id="outline-container-sec-1-4-5" class="outline-4">
<h4 id="sec-1-4-5">Hex computation</h4>
<div class="outline-text-4" id="text-1-4-5">
<p>
As with Times computation, the following code allows Computation with
Hex values in Org-mode tables using the <code>with-hex</code> macro.
</p>

<p>
Here is the code implementing this macro.
</p>
<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">org-hex-strip-lead</span> (str)
  (<span style="color: #859900;">if</span> (<span style="color: #b58900;">and</span> (<span style="color: #b58900;">&gt;</span> (length str) 2) (string= (substring str 0 2) <span style="color: #2aa198;">"0x"</span>))
      (substring str 2) str))

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">org-hex-to-hex</span> (int)
  (format <span style="color: #2aa198;">"0x%x"</span> int))

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">org-hex-to-dec</span> (str)
  (<span style="color: #859900;">cond</span>
   ((<span style="color: #b58900;">and</span> (stringp str)
         (string-match <span style="color: #2aa198;">"</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">(</span><span style="color: #2aa198;">[0-9a-f]+</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">)</span><span style="color: #2aa198;">"</span> (setf str (org-hex-strip-lead str))))
    (<span style="color: #859900;">let</span> ((out 0))
      (mapc
       (<span style="color: #b58900;">lambda</span> (ch)
         (setf out (<span style="color: #b58900;">+</span> (* out 16)
                      (<span style="color: #859900;">if</span> (<span style="color: #b58900;">and</span> (<span style="color: #b58900;">&gt;=</span> ch 48) (<span style="color: #b58900;">&lt;=</span> ch 57)) (<span style="color: #b58900;">-</span> ch 48) (<span style="color: #b58900;">-</span> ch 87)))))
       (coerce (match-string 1 str) 'list))
      out))
   ((stringp str) (string-to-number str))
   (t str)))

(<span style="color: #859900;">defmacro</span> <span style="color: #268bd2;">with-hex</span> (hex-output-p <span style="color: #b58900;">&amp;rest</span> exprs)
  <span style="color: #2aa198; font-style: italic;">"Evaluate an org-table formula, converting all fields that look</span>
<span style="color: #2aa198; font-style: italic;">    like hexadecimal to decimal integers.  If HEX-OUTPUT-P then</span>
<span style="color: #2aa198; font-style: italic;">    return the result as a hex value."</span>
  (list
   (<span style="color: #859900;">if</span> hex-output-p 'org-hex-to-hex 'identity)
   (cons 'progn
         (mapcar
          (<span style="color: #b58900;">lambda</span> (expr)
            `,(cons (car expr)
                    (mapcar (<span style="color: #b58900;">lambda</span> (el)
                              (<span style="color: #859900;">if</span> (listp el)
                                  (list 'with-hex <span style="color: #b58900;">nil</span> el)
                                (org-hex-to-dec el)))
                            (cdr expr))))
          `,@exprs))))
</pre>
</div>

<p>
Which allows the following forms of table manipulation such as adding
and subtracting hex values.
</p>
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">


<colgroup>
<col class="right"/>

<col class="right"/>

<col class="right"/>

<col class="right"/>
</colgroup>
<tbody>
<tr>
<td class="right">0x10</td>
<td class="right">0x0</td>
<td class="right">0x10</td>
<td class="right">16</td>
</tr>

<tr>
<td class="right">0x20</td>
<td class="right">0x1</td>
<td class="right">0x21</td>
<td class="right">33</td>
</tr>

<tr>
<td class="right">0x30</td>
<td class="right">0x2</td>
<td class="right">0x32</td>
<td class="right">50</td>
</tr>

<tr>
<td class="right">0xf0</td>
<td class="right">0xf</td>
<td class="right">0xff</td>
<td class="right">255</td>
</tr>
</tbody>
</table>
</div>
</div>
<div id="outline-container-field-coordinates-in-formulas" class="outline-4">
<h4 id="field-coordinates-in-formulas"><a id="sec-1-4-6" name="sec-1-4-6"></a>Field coordinates in formulas (<code>@#</code> and <code>$#</code>)</h4>
<div class="outline-text-4" id="text-field-coordinates-in-formulas">
<p>
&#x2013; Michael Brand
</p>

<p>
Following are some use cases that can be implemented with the “field
coordinates in formulas” described in the corresponding chapter in the
<a href="http://orgmode.org/manual/References.html#References">Org manual</a>.
</p>
</div>

<ul class="org-ul"><li>Copy a column from a remote table into a column<br/><div class="outline-text-5" id="text-field-coordinates-in-formulas-copy-col-to-col">

<p>
current column <code>$3</code> = remote column <code>$2</code>:
</p>
<pre class="example">
#+TBLFM: $3 = remote(FOO, @@#$2)
</pre>
</div>
</li>
<li>Copy a row from a remote table transposed into a column<br/><div class="outline-text-5" id="text-field-coordinates-in-formulas-copy-row-to-col">

<p>
current column <code>$1</code> = transposed remote row <code>@1</code>:
</p>
<pre class="example">
#+TBLFM: $1 = remote(FOO, @$#$@#)
</pre>
</div>
</li>
<li>Transpose table<br/><div class="outline-text-5" id="text-field-coordinates-in-formulas-transpose-table">

<p>
&#x2013; Michael Brand
</p>

<p>
This is more like a demonstration of using “field coordinates in formulas”
and is bound to be slow for large tables. See the discussion in the mailing
list on
<a href="http://thread.gmane.org/gmane.emacs.orgmode/22610/focus=23662">gmane</a> or
<a href="http://lists.gnu.org/archive/html/emacs-orgmode/2010-04/msg00086.html">gnu</a>.
For more efficient solutions see
<a href="org-hacks.html#transpose-table">Worg</a>.
</p>

<p>
To transpose this 4x7 table
</p>

<pre class="example">
#+TBLNAME: FOO
| year | 2004 | 2005 | 2006 | 2007 | 2008 | 2009 |
|------+------+------+------+------+------+------|
| min  |  401 |  501 |  601 |  701 |  801 |  901 |
| avg  |  402 |  502 |  602 |  702 |  802 |  902 |
| max  |  403 |  503 |  603 |  703 |  803 |  903 |
</pre>

<p>
start with a 7x4 table without any horizontal line (to have filled
also the column header) and yet empty:
</p>

<pre class="example">
|   |   |   |   |
|   |   |   |   |
|   |   |   |   |
|   |   |   |   |
|   |   |   |   |
|   |   |   |   |
|   |   |   |   |
</pre>

<p>
Then add the <code>TBLFM</code> line below.  After recalculation this will end up with
the transposed copy:
</p>

<pre class="example">
| year | min | avg | max |
| 2004 | 401 | 402 | 403 |
| 2005 | 501 | 502 | 503 |
| 2006 | 601 | 602 | 603 |
| 2007 | 701 | 702 | 703 |
| 2008 | 801 | 802 | 803 |
| 2009 | 901 | 902 | 903 |
#+TBLFM: @&lt;$&lt;..@&gt;$&gt; = remote(FOO, @$#$@#)
</pre>

<p>
The formula simply exchanges row and column numbers by taking
</p>
<ul class="org-ul">
<li>the absolute remote row number <code>@$#</code> from the current column number <code>$#</code>
</li>
<li>the absolute remote column number <code>$@#</code> from the current row number <code>@#</code>
</li>
</ul>

<p>
Formulas to be taken over from the remote table will have to be transformed
manually.
</p>
</div>
</li>
<li>Dynamic variation of ranges<br/><div class="outline-text-5" id="text-1-4-6-4">
<p>
&#x2013; Michael Brand
</p>

<p>
In this example all columns next to <code>quote</code> are calculated from the column
<code>quote</code> and show the average change of the time series <code>quote[year]</code>
during the period of the preceding <code>1</code>, <code>2</code>, <code>3</code> or <code>4</code> years:
</p>

<pre class="example">
| year | quote |   1 a |   2 a |   3 a |   4 a |
|------+-------+-------+-------+-------+-------|
| 2005 |    10 |       |       |       |       |
| 2006 |    12 | 0.200 |       |       |       |
| 2007 |    14 | 0.167 | 0.183 |       |       |
| 2008 |    16 | 0.143 | 0.155 | 0.170 |       |
| 2009 |    18 | 0.125 | 0.134 | 0.145 | 0.158 |
#+TBLFM: @I$3..@&gt;$&gt;=if(@# &gt;= $#, ($2 / subscr(@-I$2..@+I$2, @# + 1 - $#)) ^ (1 / ($# - 2)) - 1, string("")) +.0; f-3
</pre>

<p>
The important part of the formula without the field blanking is:
</p>

<pre class="example">
($2 / subscr(@-I$2..@+I$2, @# + 1 - $#)) ^ (1 / ($# - 2)) - 1
</pre>

<p>
which is the Emacs Calc implementation of the equation
</p>

<p>
<i>AvgChange(i, a) = (quote[i] / quote[i - a]) ^ (1 / a) - 1</i>
</p>

<p>
where <i>i</i> is the current time and <i>a</i> is the length of the preceding period.
</p>
</div>
</li></ul>
</div>
<div id="outline-container-column-sequence-in-row" class="outline-4">
<h4 id="column-sequence-in-row"><a id="sec-1-4-7" name="sec-1-4-7"></a>Change the column sequence in one row only</h4>
<div class="outline-text-4" id="text-column-sequence-in-row">

<p>
&#x2013; Michael Brand
</p>

<p>
The functions below can be used to change the column sequence in one row
only, without affecting the other rows above and below like with M-&lt;left&gt; or
M-&lt;right&gt; (org-table-move-column). Please see the docstring of the functions
for more explanations. Below is one example per function, with this original
table as the starting point for each example:
</p>
<pre class="example">
| a | b | c  | d  |
| e | 9 | 10 | 11 |
| f | g | h  | i  |
</pre>
</div>

<ul class="org-ul"><li>Move in row left<br/><div class="outline-text-5" id="text-1-4-7-1">
<ol class="org-ol">
<li>place point at "10" in original table
</li>
<li>result of M-x my-org-table-move-column-in-row-left:
<pre class="example">
| a | b  | c | d  |
| e | 10 | 9 | 11 |
| f | g  | h | i  |
</pre>
</li>
</ol>
</div>
</li>
<li>Move in row right<br/><div class="outline-text-5" id="text-1-4-7-2">
<ol class="org-ol">
<li>place point at "9" in original table
</li>
<li>result of M-x my-org-table-move-column-in-row-right:
<pre class="example">
| a | b  | c | d  |
| e | 10 | 9 | 11 |
| f | g  | h | i  |
</pre>
</li>
</ol>
</div>
</li>
<li>Rotate in row left<br/><div class="outline-text-5" id="text-1-4-7-3">
<ol class="org-ol">
<li>place point at "9" in original table
</li>
<li>result of M-x my-org-table-rotate-column-in-row-left:
<pre class="example">
| a | b  | c  | d |
| e | 10 | 11 | 9 |
| f | g  | h  | i |
</pre>
</li>
</ol>
</div>
</li>
<li>Rotate in row right<br/><div class="outline-text-5" id="text-1-4-7-4">
<ol class="org-ol">
<li>place point at "9" in original table
</li>
<li>result of M-x my-org-table-rotate-column-in-row-right:
<pre class="example">
| a | b  | c | d  |
| e | 11 | 9 | 10 |
| f | g  | h | i  |
</pre>
</li>
</ol>
</div>
</li>
<li>The functions<br/><div class="outline-text-5" id="text-1-4-7-5">
<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">my-org-table-move-column-in-row-right</span> ()
  <span style="color: #2aa198; font-style: italic;">"Move column to the right, limited to the current row."</span>
  (interactive)
  (my-org-table-move-column-in-row <span style="color: #b58900;">nil</span>))
(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">my-org-table-move-column-in-row-left</span> ()
  <span style="color: #2aa198; font-style: italic;">"Move column to the left, limited to the current row."</span>
  (interactive)
  (my-org-table-move-column-in-row 'left))

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">my-org-table-move-column-in-row</span> (<span style="color: #b58900;">&amp;optional</span> left)
  <span style="color: #2aa198; font-style: italic;">"Move the current column to the right, limited to the current row.</span>
<span style="color: #2aa198; font-style: italic;">With arg LEFT, move to the left.  For repeated invocation the point follows</span>
<span style="color: #2aa198; font-style: italic;">the value and changes to the target colum.  Does not fix formulas."</span>
  <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">derived from `</span><span style="color: #93a1a1; font-weight: bold;">org-table-move-column</span><span style="color: #93a1a1;">'</span>
  (interactive <span style="color: #2aa198;">"P"</span>)
  (<span style="color: #859900;">if</span> (<span style="color: #b58900;">not </span>(org-at-table-p))
      (<span style="color: #cb4b16; font-weight: bold; text-decoration: underline;">error</span> <span style="color: #2aa198;">"Not at a table"</span>))
  (org-table-find-dataline)
  (org-table-check-inside-data-field)
  (<span style="color: #859900;">let*</span> ((col (org-table-current-column))
         (col1 (<span style="color: #859900;">if</span> left (1- col) col))
         <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">Current cursor position</span>
         (colpos (<span style="color: #859900;">if</span> left (1- col) (1+ col))))
    (<span style="color: #859900;">if</span> (<span style="color: #b58900;">and</span> left (= col 1))
        (<span style="color: #cb4b16; font-weight: bold; text-decoration: underline;">error</span> <span style="color: #2aa198;">"Cannot move column further left"</span>))
    (<span style="color: #859900;">if</span> (<span style="color: #b58900;">and</span> (<span style="color: #b58900;">not </span>left) (looking-at <span style="color: #2aa198;">"[</span><span style="color: #2aa198; font-weight: bold;">^</span><span style="color: #2aa198;">|\n]*|[</span><span style="color: #2aa198; font-weight: bold;">^</span><span style="color: #2aa198;">|\n]*$"</span>))
        (<span style="color: #cb4b16; font-weight: bold; text-decoration: underline;">error</span> <span style="color: #2aa198;">"Cannot move column further right"</span>))
    (org-table-goto-column col1 t)
    (<span style="color: #b58900;">and</span> (looking-at <span style="color: #2aa198;">"|</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">(</span><span style="color: #2aa198;">[</span><span style="color: #2aa198; font-weight: bold;">^</span><span style="color: #2aa198;">|\n]+</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">)</span><span style="color: #2aa198;">|</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">(</span><span style="color: #2aa198;">[</span><span style="color: #2aa198; font-weight: bold;">^</span><span style="color: #2aa198;">|\n]+</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">)</span><span style="color: #2aa198;">|"</span>)
         (replace-match <span style="color: #2aa198;">"|\\2|\\1|"</span>))
    (org-table-goto-column colpos)
    (org-table-align)))

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">my-org-table-rotate-column-in-row-right</span> ()
  <span style="color: #2aa198; font-style: italic;">"Rotate column to the right, limited to the current row."</span>
  (interactive)
  (my-org-table-rotate-column-in-row <span style="color: #b58900;">nil</span>))
(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">my-org-table-rotate-column-in-row-left</span> ()
  <span style="color: #2aa198; font-style: italic;">"Rotate column to the left, limited to the current row."</span>
  (interactive)
  (my-org-table-rotate-column-in-row 'left))

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">my-org-table-rotate-column-in-row</span> (<span style="color: #b58900;">&amp;optional</span> left)
  <span style="color: #2aa198; font-style: italic;">"Rotate the current column to the right, limited to the current row.</span>
<span style="color: #2aa198; font-style: italic;">With arg LEFT, rotate to the left.  The boundaries of the rotation range are</span>
<span style="color: #2aa198; font-style: italic;">the current and the most right column for both directions.  For repeated</span>
<span style="color: #2aa198; font-style: italic;">invocation the point stays on the current column.  Does not fix formulas."</span>
  <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">derived from `</span><span style="color: #93a1a1; font-weight: bold;">org-table-move-column</span><span style="color: #93a1a1;">'</span>
  (interactive <span style="color: #2aa198;">"P"</span>)
  (<span style="color: #859900;">if</span> (<span style="color: #b58900;">not </span>(org-at-table-p))
      (<span style="color: #cb4b16; font-weight: bold; text-decoration: underline;">error</span> <span style="color: #2aa198;">"Not at a table"</span>))
  (org-table-find-dataline)
  (org-table-check-inside-data-field)
  (<span style="color: #859900;">let</span> ((col (org-table-current-column)))
    (org-table-goto-column col t)
    (<span style="color: #b58900;">and</span> (looking-at (<span style="color: #859900;">if</span> left
                         <span style="color: #2aa198;">"|</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">(</span><span style="color: #2aa198;">[</span><span style="color: #2aa198; font-weight: bold;">^</span><span style="color: #2aa198;">|\n]+</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">)</span><span style="color: #2aa198;">|</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">(</span><span style="color: #2aa198;">[</span><span style="color: #2aa198; font-weight: bold;">^</span><span style="color: #2aa198;">\n]+</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">)</span><span style="color: #2aa198;">|$"</span>
                       <span style="color: #2aa198;">"|</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">(</span><span style="color: #2aa198;">[</span><span style="color: #2aa198; font-weight: bold;">^</span><span style="color: #2aa198;">\n]+</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">)</span><span style="color: #2aa198;">|</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">(</span><span style="color: #2aa198;">[</span><span style="color: #2aa198; font-weight: bold;">^</span><span style="color: #2aa198;">|\n]+</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">)</span><span style="color: #2aa198;">|$"</span>))
         (replace-match <span style="color: #2aa198;">"|\\2|\\1|"</span>))
    (org-table-goto-column col)
    (org-table-align)))
</pre>
</div>
</div>
</li>
<li>Key bindings<br/><div class="outline-text-5" id="text-1-4-7-6">
<p>
As hack I have this in an Org buffer to change temporarily to the desired
behavior with C-c C-c on one of the three snippets:
</p>
<pre class="example">
- move in row:
  #+begin_src emacs-lisp :results silent
    (org-defkey org-mode-map [(meta left)]
                'my-org-table-move-column-in-row-left)
    (org-defkey org-mode-map [(meta right)]
                'my-org-table-move-column-in-row-right)
    (org-defkey org-mode-map [(left)]  'org-table-previous-field)
    (org-defkey org-mode-map [(right)] 'org-table-next-field)
  #+end_src

- rotate in row:
  #+begin_src emacs-lisp :results silent
    (org-defkey org-mode-map [(meta left)]
                'my-org-table-rotate-column-in-row-left)
    (org-defkey org-mode-map [(meta right)]
                'my-org-table-rotate-column-in-row-right)
    (org-defkey org-mode-map [(left)]  'org-table-previous-field)
    (org-defkey org-mode-map [(right)] 'org-table-next-field)
  #+end_src

- back to original:
  #+begin_src emacs-lisp :results silent
    (org-defkey org-mode-map [(meta left)]  'org-metaleft)
    (org-defkey org-mode-map [(meta right)] 'org-metaright)
    (org-defkey org-mode-map [(left)]  'backward-char)
    (org-defkey org-mode-map [(right)] 'forward-char)
  #+end_src
</pre>
</div>
</li>
<li>reasons why this is not put into the Org core<br/><div class="outline-text-5" id="text-1-4-7-7">
<p>
I consider this as only a hack for several reasons:
</p>
<ul class="org-ul">
<li>Generalization:  The existing org-table-move-column function could be
enhanced with additional optional parameters to incorporate these
functionalities and could be used as the only function for better
maintainability.  Now it's only a copy/paste hack of several similar
functions with simple modifications.
</li>
<li>Bindings:  Should be convenient for repetition like M-&lt;right&gt;.  What
should be bound where, what has to be left unbound?
</li>
<li>Does not fix formulas.  Could be resolved for field formulas but
most probably not for column or range formulas and this can lead
to confusion.  AFAIK all "official" table manipulations fix formulas.
</li>
<li>Completeness:  Not all variations and combinations are covered yet
<ul class="org-ul">
<li>left-right, up-down
</li>
<li>move, rotate with range to end, rotate with range to begin
</li>
<li>whole column/row, only in-row/in-column
</li>
</ul>
</li>
</ul>
</div>
</li></ul>
</div>
</div>
<div id="outline-container-sec-1-5" class="outline-3">
<h3 id="sec-1-5">Capture and Remember</h3>
<div class="outline-text-3" id="text-1-5">
</div><div id="outline-container-sec-1-5-1" class="outline-4">
<h4 id="sec-1-5-1">Customize the size of the frame for remember</h4>
<div class="outline-text-4" id="text-1-5-1">
<p>
(Note: this hack is likely out of date due to the development of
<i>org-capture</i>.)
</p>

<p>
#FIXME: gmane link?
On emacs-orgmode, Ryan C. Thompson suggested this:
</p>

<blockquote>
<p>
I am using org-remember set to open a new frame when used,
and the default frame size is much too large. To fix this, I have
designed some advice and a custom variable to implement custom
parameters for the remember frame:
</p>
</blockquote>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defcustom</span> <span style="color: #268bd2;">remember-frame-alist</span> <span style="color: #b58900;">nil</span>
  <span style="color: #2aa198; font-style: italic;">"Additional frame parameters for dedicated remember frame."</span>
  <span style="color: #657b83; font-style: italic;">:type</span> 'alist
  <span style="color: #657b83; font-style: italic;">:group</span> 'remember)

(<span style="color: #859900;">defadvice</span> <span style="color: #268bd2;">remember</span> (around remember-frame-parameters activate)
  <span style="color: #2aa198; font-style: italic;">"Set some frame parameters for the remember frame."</span>
  (<span style="color: #859900;">let</span> ((default-frame-alist (append remember-frame-alist
                                     default-frame-alist)))
    ad-do-it))
</pre>
</div>

<p>
Setting remember-frame-alist to <code>((width . 80) (height . 15)))</code> give a
reasonable size for the frame.
</p>
</div>
</div>
</div>

<div id="outline-container-sec-1-6" class="outline-3">
<h3 id="sec-1-6">Handling Links</h3>
<div class="outline-text-3" id="text-1-6">
</div><div id="outline-container-sec-1-6-1" class="outline-4">
<h4 id="sec-1-6-1"><a href="#heading-to-link">Turn a heading into an org link</a></h4>
</div>
<div id="outline-container-sec-1-6-2" class="outline-4">
<h4 id="sec-1-6-2">Quickaccess to the link part of hyperlinks</h4>
<div class="outline-text-4" id="text-1-6-2">
<p>
Christian Moe <a href="http://permalink.gmane.org/gmane.emacs.orgmode/43122">asked</a>, if there is a simpler way to copy the link part
of an org hyperling other than to use `C-c C-l C-a C-k C-g', 
which is indeed kind of cumbersome.
</p>

<p>
The thread offered <a href="http://permalink.gmane.org/gmane.emacs.orgmode/43606">two ways</a>:
</p>

<p>
Using a <a href="http://www.gnu.org/software/emacs/manual/html_node/emacs/Keyboard-Macros.html">keyboard macro</a>:
</p>
<div class="org-src-container">

<pre class="src src-emacs-lisp">(fset 'getlink
      (<span style="color: #b58900;">lambda</span> (<span style="color: #b58900;">&amp;optional</span> arg) 
        <span style="color: #2aa198; font-style: italic;">"Keyboard macro."</span> 
        (interactive <span style="color: #2aa198;">"p"</span>) 
        (kmacro-exec-ring-item (quote (<span style="color: #2aa198;">"\C-c\C-l\C-a\C-k\C-g"</span> 0 <span style="color: #2aa198;">"%d"</span>)) arg)))
</pre>
</div>

<p>
or a function: 
</p>
<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">my-org-extract-link</span> ()
  <span style="color: #2aa198; font-style: italic;">"Extract the link location at point and put it on the killring."</span>
  (interactive)
  (<span style="color: #859900;">when</span> (org-in-regexp org-bracket-link-regexp 1)
    (kill-new (org-link-unescape (org-match-string-no-properties 1)))))
</pre>
</div>

<p>
They put the link destination on the killring and can be easily bound to a key.
</p>
</div>
</div>
<div id="outline-container-sec-1-6-3" class="outline-4">
<h4 id="sec-1-6-3">Insert link with HTML title as default description</h4>
<div class="outline-text-4" id="text-1-6-3">
<p>
When using `org-insert-link' (`C-c C-l') it might be useful to extract contents
from HTML &lt;title&gt; tag and use it as a default link description. Here is a way to
accomplish this:
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">require</span> '<span style="color: #268bd2; font-weight: bold;">mm-url</span>) <span style="color: #93a1a1; font-style: italic;">; </span><span style="color: #93a1a1;">to include mm-url-decode-entities-string</span>

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">my-org-insert-link</span> ()
  <span style="color: #2aa198; font-style: italic;">"Insert org link where default description is set to html title."</span>
  (interactive)
  (<span style="color: #859900;">let*</span> ((url (read-string <span style="color: #2aa198;">"URL: "</span>))
         (title (get-html-title-from-url url)))
    (org-insert-link <span style="color: #b58900;">nil</span> url title)))

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">get-html-title-from-url</span> (url)
  <span style="color: #2aa198; font-style: italic;">"Return content in &lt;title&gt; tag."</span>
  (<span style="color: #859900;">let</span> (x1 x2 (download-buffer (url-retrieve-synchronously url)))
    (<span style="color: #859900;">save-excursion</span>
      (set-buffer download-buffer)
      (beginning-of-buffer)
      (setq x1 (search-forward <span style="color: #2aa198;">"&lt;title&gt;"</span>))
      (search-forward <span style="color: #2aa198;">"&lt;/title&gt;"</span>)
      (setq x2 (search-backward <span style="color: #2aa198;">"&lt;"</span>))
      (mm-url-decode-entities-string (buffer-substring-no-properties x1 x2)))))
</pre>
</div>

<p>
Then just use `M-x my-org-insert-link' instead of `org-insert-link'.
</p>
</div>
</div>
</div>
<div id="outline-container-sec-1-7" class="outline-3">
<h3 id="sec-1-7">Archiving Content in Org-Mode</h3>
<div class="outline-text-3" id="text-1-7">
</div><div id="outline-container-sec-1-7-1" class="outline-4">
<h4 id="sec-1-7-1">Preserve top level headings when archiving to a file</h4>
<div class="outline-text-4" id="text-1-7-1">
<ul class="org-ul">
<li>Matt Lundin
</li>
</ul>

<p>
To preserve (somewhat) the integrity of your archive structure while
archiving lower level items to a file, you can use the following
defadvice:
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defadvice</span> <span style="color: #268bd2;">org-archive-subtree</span> (around my-org-archive-subtree activate)
  (<span style="color: #859900;">let</span> ((org-archive-location
         (<span style="color: #859900;">if</span> (<span style="color: #859900;">save-excursion</span> (org-back-to-heading)
                             (<span style="color: #b58900;">&gt;</span> (org-outline-level) 1))
             (concat (car (split-string org-archive-location <span style="color: #2aa198;">"::"</span>))
                     <span style="color: #2aa198;">"::* "</span>
                     (car (org-get-outline-path)))
           org-archive-location)))
    ad-do-it))
</pre>
</div>

<p>
Thus, if you have an outline structure such as&#x2026;
</p>

<div class="org-src-container">

<pre class="src src-org"><span style="color: #cb4b16;">* Heading</span>
<span style="color: #fdf6e3;">*</span><span style="color: #859900;">* Subheading</span>
<span style="color: #fdf6e3;">**</span><span style="color: #268bd2;">* Subsubheading</span>
</pre>
</div>

<p>
&#x2026;archiving "Subsubheading" to a new file will set the location in
the new file to the top level heading:
</p>

<div class="org-src-container">

<pre class="src src-org"><span style="color: #cb4b16;">* Heading</span>
<span style="color: #fdf6e3;">*</span><span style="color: #859900;">* Subsubheading</span>
</pre>
</div>

<p>
While this hack obviously destroys the outline hierarchy somewhat, it
at least preserves the logic of level one groupings.
</p>

<p>
A slightly more complex version of this hack will not only keep the
archive organized by top-level headings, but will also preserve the
tags found on those headings:
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">my-org-inherited-no-file-tags</span> ()
  (<span style="color: #859900;">let</span> ((tags (org-entry-get <span style="color: #b58900;">nil</span> <span style="color: #2aa198;">"ALLTAGS"</span> 'selective))
        (ltags (org-entry-get <span style="color: #b58900;">nil</span> <span style="color: #2aa198;">"TAGS"</span>)))
    (mapc (<span style="color: #b58900;">lambda</span> (tag)
            (setq tags
                  (replace-regexp-in-string (concat tag <span style="color: #2aa198;">":"</span>) <span style="color: #2aa198;">""</span> tags)))
          (append org-file-tags (<span style="color: #859900;">when</span> ltags (split-string ltags <span style="color: #2aa198;">":"</span> t))))
    (<span style="color: #859900;">if</span> (string= <span style="color: #2aa198;">":"</span> tags) <span style="color: #b58900;">nil</span> tags)))

(<span style="color: #859900;">defadvice</span> <span style="color: #268bd2;">org-archive-subtree</span> (around my-org-archive-subtree-low-level activate)
  (<span style="color: #859900;">let</span> ((tags (my-org-inherited-no-file-tags))
        (org-archive-location
         (<span style="color: #859900;">if</span> (<span style="color: #859900;">save-excursion</span> (org-back-to-heading)
                             (<span style="color: #b58900;">&gt;</span> (org-outline-level) 1))
             (concat (car (split-string org-archive-location <span style="color: #2aa198;">"::"</span>))
                     <span style="color: #2aa198;">"::* "</span>
                     (car (org-get-outline-path)))
           org-archive-location)))
    ad-do-it
    (<span style="color: #859900;">with-current-buffer</span> (find-file-noselect (org-extract-archive-file))
      (<span style="color: #859900;">save-excursion</span>
        (<span style="color: #859900;">while</span> (org-up-heading-safe))
        (org-set-tags-to tags)))))
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-1-7-2" class="outline-4">
<h4 id="sec-1-7-2">Archive in a date tree</h4>
<div class="outline-text-4" id="text-1-7-2">
<p>
Posted to Org-mode mailing list by Osamu Okano <span class="timestamp-wrapper"><span class="timestamp">[2010-04-21 Wed]</span></span>.
</p>

<p>
(Make sure org-datetree.el is loaded for this to work.)
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp"><span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">(setq org-archive-location "%s_archive::date-tree")</span>
(<span style="color: #859900;">defadvice</span> <span style="color: #268bd2;">org-archive-subtree</span>
  (around org-archive-subtree-to-data-tree activate)
  <span style="color: #2aa198; font-style: italic;">"org-archive-subtree to date-tree"</span>
  (<span style="color: #859900;">if</span>
      (string= <span style="color: #2aa198;">"date-tree"</span>
               (org-extract-archive-heading
                (org-get-local-archive-location)))
      (<span style="color: #859900;">let*</span> ((dct (decode-time (org-current-time)))
             (y (nth 5 dct))
             (m (nth 4 dct))
             (d (nth 3 dct))
             (this-buffer (current-buffer))
             (location (org-get-local-archive-location))
             (afile (org-extract-archive-file location))
             (org-archive-location
              (format <span style="color: #2aa198;">"%s::*** %04d-%02d-%02d %s"</span> afile y m d
                      (format-time-string <span style="color: #2aa198;">"%A"</span> (encode-time 0 0 0 d m y)))))
        (message <span style="color: #2aa198;">"afile=%s"</span> afile)
        (<span style="color: #859900;">unless</span> afile
          (<span style="color: #cb4b16; font-weight: bold; text-decoration: underline;">error</span> <span style="color: #2aa198;">"Invalid `</span><span style="color: #2aa198; font-weight: bold;">org-archive-location</span><span style="color: #2aa198;">'"</span>))
        (<span style="color: #859900;">save-excursion</span>
          (switch-to-buffer (find-file-noselect afile))
          (org-datetree-find-year-create y)
          (org-datetree-find-month-create y m)
          (org-datetree-find-day-create y m d)
          (widen)
          (switch-to-buffer this-buffer))
        ad-do-it)
    ad-do-it))
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-1-7-3" class="outline-4">
<h4 id="sec-1-7-3">Add inherited tags to archived entries</h4>
<div class="outline-text-4" id="text-1-7-3">
<p>
To make <code>org-archive-subtree</code> keep inherited tags, Osamu OKANO suggests to
advise the function like this:
</p>

<pre class="example">
(defadvice org-archive-subtree
  (before add-inherited-tags-before-org-archive-subtree activate)
    "add inherited tags before org-archive-subtree"
    (org-set-tags-to (org-get-tags-at)))
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-1-8" class="outline-3">
<h3 id="sec-1-8">Using and Managing Org-Metadata</h3>
<div class="outline-text-3" id="text-1-8">
</div><div id="outline-container-sec-1-8-1" class="outline-4">
<h4 id="sec-1-8-1">Remove redundant tags of headlines</h4>
<div class="outline-text-4" id="text-1-8-1">
<p>
&#x2013; David Maus
</p>

<p>
A small function that processes all headlines in current buffer and
removes tags that are local to a headline and inherited by a parent
headline or the #+FILETAGS: statement.
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">dmj/org-remove-redundant-tags</span> ()
  <span style="color: #2aa198; font-style: italic;">"Remove redundant tags of headlines in current buffer.</span>

<span style="color: #2aa198; font-style: italic;">A tag is considered redundant if it is local to a headline and</span>
<span style="color: #2aa198; font-style: italic;">inherited by a parent headline."</span>
  (interactive)
  (<span style="color: #859900;">when</span> (eq major-mode 'org-mode)
    (<span style="color: #859900;">save-excursion</span>
      (org-map-entries
       '(<span style="color: #b58900;">lambda</span> ()
          (<span style="color: #859900;">let</span> ((alltags (split-string (<span style="color: #b58900;">or</span> (org-entry-get (point) <span style="color: #2aa198;">"ALLTAGS"</span>) <span style="color: #2aa198;">""</span>) <span style="color: #2aa198;">":"</span>))
                local inherited tag)
            (<span style="color: #859900;">dolist</span> (tag alltags)
              (<span style="color: #859900;">if</span> (get-text-property 0 'inherited tag)
                  (push tag inherited) (push tag local)))
            (<span style="color: #859900;">dolist</span> (tag local)
              (<span style="color: #859900;">if</span> (member tag inherited) (org-toggle-tag tag 'off)))))
       t <span style="color: #b58900;">nil</span>))))
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-1-8-2" class="outline-4">
<h4 id="sec-1-8-2">Remove empty property drawers</h4>
<div class="outline-text-4" id="text-1-8-2">
<p>
David Maus proposed this:
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">dmj:org:remove-empty-propert-drawers</span> ()
  <span style="color: #2aa198; font-style: italic;">"*Remove all empty property drawers in current file."</span>
  (interactive)
  (<span style="color: #859900;">unless</span> (eq major-mode 'org-mode)
    (<span style="color: #cb4b16; font-weight: bold; text-decoration: underline;">error</span> <span style="color: #2aa198;">"You need to turn on Org mode for this function."</span>))
  (<span style="color: #859900;">save-excursion</span>
    (goto-char (point-min))
    (<span style="color: #859900;">while</span> (re-search-forward <span style="color: #2aa198;">":PROPERTIES:"</span> <span style="color: #b58900;">nil</span> t)
      (<span style="color: #859900;">save-excursion</span>
    (org-remove-empty-drawer-at <span style="color: #2aa198;">"PROPERTIES"</span> (match-beginning 0))))))
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-1-8-3" class="outline-4">
<h4 id="sec-1-8-3">Group task list by a property</h4>
<div class="outline-text-4" id="text-1-8-3">
<p>
This advice allows you to group a task list in Org-Mode.  To use it,
set the variable <code>org-agenda-group-by-property</code> to the name of a
property in the option list for a TODO or TAGS search.  The resulting
agenda view will group tasks by that property prior to searching.
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defvar</span> <span style="color: #268bd2;">org-agenda-group-by-property</span> <span style="color: #b58900;">nil</span>
  <span style="color: #2aa198; font-style: italic;">"Set this in org-mode agenda views to group tasks by property"</span>)

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">org-group-bucket-items</span> (prop items)
  (<span style="color: #859900;">let</span> ((buckets ()))
    (<span style="color: #859900;">dolist</span> (item items)
      (<span style="color: #859900;">let*</span> ((marker (get-text-property 0 'org-marker item))
             (pvalue (org-entry-get marker prop t))
             (cell (assoc pvalue buckets)))
        (<span style="color: #859900;">if</span> cell
            (setcdr cell (cons item (cdr cell)))
          (setq buckets (cons (cons pvalue (list item))
                              buckets)))))
    (setq buckets (mapcar (<span style="color: #b58900;">lambda</span> (bucket)
                            (cons (car bucket)
                                  (reverse (cdr bucket))))
                          buckets))
    (sort buckets (<span style="color: #b58900;">lambda</span> (i1 i2)
                    (string&lt; (car i1) (car i2))))))

(<span style="color: #859900;">defadvice</span> <span style="color: #268bd2;">org-finalize-agenda-entries</span> (around org-group-agenda-finalize
                                               (list <span style="color: #b58900;">&amp;optional</span> nosort))
  <span style="color: #2aa198; font-style: italic;">"Prepare bucketed agenda entry lists"</span>
  (<span style="color: #859900;">if</span> org-agenda-group-by-property
      <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">bucketed, handle appropriately</span>
      (<span style="color: #859900;">let</span> ((text <span style="color: #2aa198;">""</span>))
        (<span style="color: #859900;">dolist</span> (bucket (org-group-bucket-items
                         org-agenda-group-by-property
                         list))
          (<span style="color: #859900;">let</span> ((header (concat <span style="color: #2aa198;">"Property "</span>
                                org-agenda-group-by-property
                                <span style="color: #2aa198;">" is "</span>
                                (<span style="color: #b58900;">or</span> (car bucket) <span style="color: #2aa198;">"&lt;nil&gt;"</span>) <span style="color: #2aa198;">":\n"</span>)))
            (add-text-properties 0 (1- (length header))
                                 (list 'face 'org-agenda-structure)
                                 header)
            (setq text
                  (concat text header
                          <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">recursively process</span>
                          (<span style="color: #859900;">let</span> ((org-agenda-group-by-property <span style="color: #b58900;">nil</span>))
                            (org-finalize-agenda-entries
                             (cdr bucket) nosort))
                          <span style="color: #2aa198;">"\n\n"</span>))))
        (setq ad-return-value text))
    ad-do-it))
(ad-activate 'org-finalize-agenda-entries)
</pre>
</div>
</div>
</div>

<div id="outline-container-sec-1-8-4" class="outline-4">
<h4 id="sec-1-8-4">A way to tag a task so that when clocking-out user is prompted to take a note.</h4>
<div class="outline-text-4" id="text-1-8-4">
<p>
Thanks to Richard Riley (see <a href="http://permalink.gmane.org/gmane.emacs.orgmode/40896">this post on the mailing list</a>).
</p>

<p>
A small hook run when clocking out of a task that prompts for a note
when the tag "<code>clockout_note</code>" is found in a headline. It uses the tag
("<code>clockout_note</code>") so inheritance can also be used&#x2026;
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">rgr/check-for-clock-out-note</span>()
      (interactive)
      (<span style="color: #859900;">save-excursion</span>
        (org-back-to-heading)
        (<span style="color: #859900;">let</span> ((tags (org-get-tags)))
          (<span style="color: #b58900;">and</span> tags (message <span style="color: #2aa198;">"tags: %s "</span> tags)
               (<span style="color: #859900;">when</span> (member <span style="color: #2aa198;">"clocknote"</span> tags)
                 (org-add-note))))))

(add-hook 'org-clock-out-hook 'rgr/check-for-clock-out-note)
</pre>
</div>
</div>
</div>

<div id="outline-container-sec-1-8-5" class="outline-4">
<h4 id="sec-1-8-5">Dynamically adjust tag position</h4>
<div class="outline-text-4" id="text-1-8-5">
<p>
Here is a bit of code that allows you to have the tags always
right-adjusted in the buffer.
</p>

<p>
This is useful when you have bigger window than default window-size
and you dislike the aesthetics of having the tag in the middle of the
line.
</p>

<p>
This hack solves the problem of adjusting it whenever you change the
window size.
Before saving it will revert the file to having the tag position be
left-adjusted so that if you track your files with version control,
you won't run into artificial diffs just because the window-size
changed.
</p>

<p>
<b>IMPORTANT</b>: This is probably slow on very big files.
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(setq ba/org-adjust-tags-column t)

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">ba/org-adjust-tags-column-reset-tags</span> ()
  <span style="color: #2aa198; font-style: italic;">"In org-mode buffers it will reset tag position according to</span>
<span style="color: #2aa198; font-style: italic;">`</span><span style="color: #2aa198; font-weight: bold; font-style: italic;">org-tags-column</span><span style="color: #2aa198; font-style: italic;">'."</span>
  (<span style="color: #859900;">when</span> (<span style="color: #b58900;">and</span>
         (<span style="color: #b58900;">not </span>(string= (buffer-name) <span style="color: #2aa198;">"*Remember*"</span>))
         (eql major-mode 'org-mode))
    (<span style="color: #859900;">let</span> ((b-m-p (buffer-modified-p)))
      (<span style="color: #859900;">condition-case</span> <span style="color: #b58900;">nil</span>
          (<span style="color: #859900;">save-excursion</span>
            (goto-char (point-min))
            (command-execute 'outline-next-visible-heading)
            <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">disable (message) that org-set-tags generates</span>
            (<span style="color: #859900;">flet</span> ((message (<span style="color: #b58900;">&amp;rest</span> ignored) <span style="color: #b58900;">nil</span>))
              (org-set-tags 1 t))
            (set-buffer-modified-p b-m-p))
        (<span style="color: #cb4b16; font-weight: bold; text-decoration: underline;">error</span> <span style="color: #b58900;">nil</span>)))))

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">ba/org-adjust-tags-column-now</span> ()
  <span style="color: #2aa198; font-style: italic;">"Right-adjust `</span><span style="color: #2aa198; font-weight: bold; font-style: italic;">org-tags-column</span><span style="color: #2aa198; font-style: italic;">' value, then reset tag position."</span>
  (set (make-local-variable 'org-tags-column)
       (<span style="color: #b58900;">-</span> (<span style="color: #b58900;">-</span> (window-width) (length org-ellipsis))))
  (ba/org-adjust-tags-column-reset-tags))

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">ba/org-adjust-tags-column-maybe</span> ()
  <span style="color: #2aa198; font-style: italic;">"If `</span><span style="color: #2aa198; font-weight: bold; font-style: italic;">ba/org-adjust-tags-column</span><span style="color: #2aa198; font-style: italic;">' is set to non-nil, adjust tags."</span>
  (<span style="color: #859900;">when</span> ba/org-adjust-tags-column
    (ba/org-adjust-tags-column-now)))

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">ba/org-adjust-tags-column-before-save</span> ()
  <span style="color: #2aa198; font-style: italic;">"Tags need to be left-adjusted when saving."</span>
  (<span style="color: #859900;">when</span> ba/org-adjust-tags-column
     (setq org-tags-column 1)
     (ba/org-adjust-tags-column-reset-tags)))

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">ba/org-adjust-tags-column-after-save</span> ()
  <span style="color: #2aa198; font-style: italic;">"Revert left-adjusted tag position done by before-save hook."</span>
  (ba/org-adjust-tags-column-maybe)
  (set-buffer-modified-p <span style="color: #b58900;">nil</span>))

<span style="color: #93a1a1; font-style: italic;">; </span><span style="color: #93a1a1;">automatically align tags on right-hand side</span>
(add-hook 'window-configuration-change-hook
          'ba/org-adjust-tags-column-maybe)
(add-hook 'before-save-hook 'ba/org-adjust-tags-column-before-save)
(add-hook 'after-save-hook 'ba/org-adjust-tags-column-after-save)
(add-hook 'org-agenda-mode-hook '(<span style="color: #b58900;">lambda</span> ()
                                  (setq org-agenda-tags-column (<span style="color: #b58900;">-</span> (window-width)))))

<span style="color: #93a1a1; font-style: italic;">; </span><span style="color: #93a1a1;">between invoking org-refile and displaying the prompt (which</span>
<span style="color: #93a1a1; font-style: italic;">; </span><span style="color: #93a1a1;">triggers window-configuration-change-hook) tags might adjust,</span>
<span style="color: #93a1a1; font-style: italic;">; </span><span style="color: #93a1a1;">which invalidates the org-refile cache</span>
(<span style="color: #859900;">defadvice</span> <span style="color: #268bd2;">org-refile</span> (around org-refile-disable-adjust-tags)
  <span style="color: #2aa198; font-style: italic;">"Disable dynamically adjusting tags"</span>
  (<span style="color: #859900;">let</span> ((ba/org-adjust-tags-column <span style="color: #b58900;">nil</span>))
    ad-do-it))
(ad-activate 'org-refile)
</pre>
</div>
</div>
</div>

<div id="outline-container-sec-1-8-6" class="outline-4">
<h4 id="sec-1-8-6">Use an "attach" link type to open files without worrying about their location</h4>
<div class="outline-text-4" id="text-1-8-6">
<p>
&#x2013; Darlan Cavalcante Moreira
</p>

<p>
In the setup part in my org-files I put:
</p>

<p>
#+begin<sub>src</sub> org
  ,#+LINK: attach elisp:(org-open-file (org-attach-expand "%s"))
#+end<sub>src</sub> org
</p>

<p>
Now I can use the "attach" link type, but org will ask me if I want to
allow executing the elisp code.  To avoid this you can even set
org-confirm-elisp-link-function to nil (I don't like this because it allows
any elisp code in links) or you can set org-confirm-elisp-link-not-regexp
appropriately.
</p>

<p>
In my case I use
</p>

<pre class="example">
(setq org-confirm-elisp-link-not-regexp "org-open-file")
</pre>

<p>
This works very well.
</p>
</div>
</div>
</div>
<div id="outline-container-sec-1-9" class="outline-3">
<h3 id="sec-1-9">Org Agenda and Task Management</h3>
<div class="outline-text-3" id="text-1-9">
</div><div id="outline-container-sec-1-9-1" class="outline-4">
<h4 id="sec-1-9-1">Make it easier to set org-agenda-files from multiple directories</h4>
<div class="outline-text-4" id="text-1-9-1">
<ul class="org-ul">
<li>Matt Lundin
</li>
</ul>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">my-org-list-files</span> (dirs ext)
  <span style="color: #2aa198; font-style: italic;">"Function to create list of org files in multiple subdirectories.</span>
<span style="color: #2aa198; font-style: italic;">This can be called to generate a list of files for</span>
<span style="color: #2aa198; font-style: italic;">org-agenda-files or org-refile-targets.</span>

<span style="color: #2aa198; font-style: italic;">DIRS is a list of directories.</span>

<span style="color: #2aa198; font-style: italic;">EXT is a list of the extensions of files to be included."</span>
  (<span style="color: #859900;">let</span> ((dirs (<span style="color: #859900;">if</span> (listp dirs)
                  dirs
                (list dirs)))
        (ext (<span style="color: #859900;">if</span> (listp ext)
                 ext
               (list ext)))
        files)
    (mapc
     (<span style="color: #b58900;">lambda</span> (x)
       (mapc
        (<span style="color: #b58900;">lambda</span> (y)
          (setq files
                (append files
                        (file-expand-wildcards
                         (concat (file-name-as-directory x) <span style="color: #2aa198;">"*"</span> y)))))
        ext))
     dirs)
    (mapc
     (<span style="color: #b58900;">lambda</span> (x)
       (<span style="color: #859900;">when</span> (<span style="color: #b58900;">or</span> (string-match <span style="color: #2aa198;">"/.#"</span> x)
                 (string-match <span style="color: #2aa198;">"#$"</span> x))
         (setq files (delete x files))))
     files)
    files))

(<span style="color: #859900;">defvar</span> <span style="color: #268bd2;">my-org-agenda-directories</span> '(<span style="color: #2aa198;">"~/org/"</span>)
  <span style="color: #2aa198; font-style: italic;">"List of directories containing org files."</span>)
(<span style="color: #859900;">defvar</span> <span style="color: #268bd2;">my-org-agenda-extensions</span> '(<span style="color: #2aa198;">".org"</span>)
  <span style="color: #2aa198; font-style: italic;">"List of extensions of agenda files"</span>)

(setq my-org-agenda-directories '(<span style="color: #2aa198;">"~/org/"</span> <span style="color: #2aa198;">"~/work/"</span>))
(setq my-org-agenda-extensions '(<span style="color: #2aa198;">".org"</span> <span style="color: #2aa198;">".ref"</span>))

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">my-org-set-agenda-files</span> ()
  (interactive)
  (setq org-agenda-files (my-org-list-files
                          my-org-agenda-directories
                          my-org-agenda-extensions)))

(my-org-set-agenda-files)
</pre>
</div>

<p>
The code above will set your "default" agenda files to all files
ending in ".org" and ".ref" in the directories "~/org/" and "~/work/".
You can change these values by setting the variables
my-org-agenda-extensions and my-org-agenda-directories. The function
my-org-agenda-files-by-filetag uses these two variables to determine
which files to search for filetags (i.e., the larger set from which
the subset will be drawn).
</p>

<p>
You can also easily use my-org-list-files to "mix and match"
directories and extensions to generate different lists of agenda
files.
</p>
</div>
</div>
<div id="outline-container-set-agenda-files-by-filetag" class="outline-4">
<h4 id="set-agenda-files-by-filetag"><a id="sec-1-9-2" name="sec-1-9-2"></a>Restrict org-agenda-files by filetag</h4>
<div class="outline-text-4" id="text-set-agenda-files-by-filetag">
<ul class="org-ul">
<li>Matt Lundin
</li>
</ul>

<p>
It is often helpful to limit yourself to a subset of your agenda
files. For instance, at work, you might want to see only files related
to work (e.g., bugs, clientA, projectxyz, etc.). The FAQ has helpful
information on filtering tasks using <a href="org-faq.html#limit-agenda-with-tag-filtering">filetags</a> and <a href="org-faq.html#limit-agenda-with-category-match">custom agenda
commands</a>. These solutions, however, require reapplying a filter each
time you call the agenda or writing several new custom agenda commands
for each context. Another solution is to use directories for different
types of tasks and to change your agenda files with a function that
sets org-agenda-files to the appropriate directory. But this relies on
hard and static boundaries between files.
</p>

<p>
The following functions allow for a more dynamic approach to selecting
a subset of files based on filetags:
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">my-org-agenda-restrict-files-by-filetag</span> (<span style="color: #b58900;">&amp;optional</span> tag)
  <span style="color: #2aa198; font-style: italic;">"Restrict org agenda files only to those containing filetag."</span>
  (interactive)
  (<span style="color: #859900;">let*</span> ((tagslist (my-org-get-all-filetags))
         (ftag (<span style="color: #b58900;">or</span> tag
                   (completing-read <span style="color: #2aa198;">"Tag: "</span>
                                    (mapcar 'car tagslist)))))
    (org-agenda-remove-restriction-lock 'noupdate)
    (put 'org-agenda-files 'org-restrict (cdr (assoc ftag tagslist)))
    (setq org-agenda-overriding-restriction 'files)))

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">my-org-get-all-filetags</span> ()
  <span style="color: #2aa198; font-style: italic;">"Get list of filetags from all default org-files."</span>
  (<span style="color: #859900;">let</span> ((files org-agenda-files)
        tagslist x)
    (<span style="color: #859900;">save-window-excursion</span>
      (<span style="color: #859900;">while</span> (setq x (pop files))
        (set-buffer (find-file-noselect x))
        (mapc
         (<span style="color: #b58900;">lambda</span> (y)
           (<span style="color: #859900;">let</span> ((tagfiles (assoc y tagslist)))
             (<span style="color: #859900;">if</span> tagfiles
                 (setcdr tagfiles (cons x (cdr tagfiles)))
               (add-to-list 'tagslist (list y x)))))
         (my-org-get-filetags)))
      tagslist)))

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">my-org-get-filetags</span> ()
  <span style="color: #2aa198; font-style: italic;">"Get list of filetags for current buffer"</span>
  (<span style="color: #859900;">let</span> ((ftags org-file-tags)
        x)
    (mapcar
     (<span style="color: #b58900;">lambda</span> (x)
       (org-substring-no-properties x))
     ftags)))
</pre>
</div>

<p>
Calling my-org-agenda-restrict-files-by-filetag results in a prompt
with all filetags in your "normal" agenda files. When you select a
tag, org-agenda-files will be restricted to only those files
containing the filetag. To release the restriction, type C-c C-x &gt;
(org-agenda-remove-restriction-lock).
</p>
</div>
</div>
<div id="outline-container-sec-1-9-3" class="outline-4">
<h4 id="sec-1-9-3">Highlight the agenda line under cursor</h4>
<div class="outline-text-4" id="text-1-9-3">
<p>
This is useful to make sure what task you are operating on.
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(add-hook 'org-agenda-mode-hook '(<span style="color: #b58900;">lambda</span> () (hl-line-mode 1)))
</pre>
</div>

<p>
Under XEmacs:
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp"><span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">hl-line seems to be only for emacs</span>
(<span style="color: #859900;">require</span> '<span style="color: #268bd2; font-weight: bold;">highline</span>)
(add-hook 'org-agenda-mode-hook '(<span style="color: #b58900;">lambda</span> () (highline-mode 1)))

<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">highline-mode does not work straightaway in tty mode.</span>
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">I use a black background</span>
(custom-set-faces
  '(highline-face ((((type tty) (class color))
                    (<span style="color: #657b83; font-style: italic;">:background</span> <span style="color: #2aa198;">"white"</span> <span style="color: #657b83; font-style: italic;">:foreground</span> <span style="color: #2aa198;">"black"</span>)))))
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-1-9-4" class="outline-4">
<h4 id="sec-1-9-4">Split frame horizontally for agenda</h4>
<div class="outline-text-4" id="text-1-9-4">
<p>
If you would like to split the frame into two side-by-side windows when
displaying the agenda, try this hack from Jan Rehders, which uses the
`toggle-window-split' from
</p>

<p>
<a href="http://www.emacswiki.org/cgi-bin/wiki/ToggleWindowSplit">http://www.emacswiki.org/cgi-bin/wiki/ToggleWindowSplit</a>
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp"><span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">Patch org-mode to use vertical splitting</span>
(<span style="color: #859900;">defadvice</span> <span style="color: #268bd2;">org-prepare-agenda</span> (after org-fix-split)
  (toggle-window-split))
(ad-activate 'org-prepare-agenda)
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-1-9-5" class="outline-4">
<h4 id="sec-1-9-5">Automatically add an appointment when clocking in a task</h4>
<div class="outline-text-4" id="text-1-9-5">
<div class="org-src-container">

<pre class="src src-emacs-lisp"><span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">Make sure you have a sensible value for `</span><span style="color: #93a1a1; font-weight: bold;">appt-message-warning-time</span><span style="color: #93a1a1;">'</span>
(<span style="color: #859900;">defvar</span> <span style="color: #268bd2;">bzg-org-clock-in-appt-delay</span> 100
  <span style="color: #2aa198; font-style: italic;">"Number of minutes for setting an appointment by clocking-in"</span>)
</pre>
</div>

<p>
This function let's you add an appointment for the current entry.
This can be useful when you need a reminder.
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">bzg-org-clock-in-add-appt</span> (<span style="color: #b58900;">&amp;optional</span> n)
  <span style="color: #2aa198; font-style: italic;">"Add an appointment for the Org entry at point in N minutes."</span>
  (interactive)
  (<span style="color: #859900;">save-excursion</span>
    (org-back-to-heading t)
    (looking-at org-complex-heading-regexp)
    (<span style="color: #859900;">let*</span> ((msg (match-string-no-properties 4))
       (ct-time (decode-time))
       (appt-min (<span style="color: #b58900;">+</span> (cadr ct-time)
            (<span style="color: #b58900;">or</span> n bzg-org-clock-in-appt-delay)))
       (appt-time <span style="color: #93a1a1; font-style: italic;">; </span><span style="color: #93a1a1;">define the time for the appointment</span>
        (<span style="color: #859900;">progn</span> (setf (cadr ct-time) appt-min) ct-time)))
      (appt-add (format-time-string
         <span style="color: #2aa198;">"%H:%M"</span> (apply 'encode-time appt-time)) msg)
      (<span style="color: #859900;">if</span> (interactive-p) (message <span style="color: #2aa198;">"New appointment for %s"</span> msg)))))
</pre>
</div>

<p>
You can advise <code>org-clock-in</code> so that <code>C-c C-x C-i</code> will automatically
add an appointment:
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defadvice</span> <span style="color: #268bd2;">org-clock-in</span> (after org-clock-in-add-appt activate)
  <span style="color: #2aa198; font-style: italic;">"Add an appointment when clocking a task in."</span>
  (bzg-org-clock-in-add-appt))
</pre>
</div>

<p>
You may also want to delete the associated appointment when clocking
out.  This function does this:
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">bzg-org-clock-out-delete-appt</span> <span style="color: #b58900;">nil</span>
  <span style="color: #2aa198; font-style: italic;">"When clocking out, delete any associated appointment."</span>
  (interactive)
  (<span style="color: #859900;">save-excursion</span>
    (org-back-to-heading t)
    (looking-at org-complex-heading-regexp)
    (<span style="color: #859900;">let*</span> ((msg (match-string-no-properties 4)))
      (setq appt-time-msg-list
        (delete <span style="color: #b58900;">nil</span>
            (mapcar
             (<span style="color: #b58900;">lambda</span> (appt)
               (<span style="color: #859900;">if</span> (<span style="color: #b58900;">not </span>(string-match (regexp-quote msg)
                          (cadr appt))) appt))
             appt-time-msg-list)))
      (appt-check))))
</pre>
</div>

<p>
And here is the advice for <code>org-clock-out</code> (<code>C-c C-x C-o</code>)
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defadvice</span> <span style="color: #268bd2;">org-clock-out</span> (before org-clock-out-delete-appt activate)
  <span style="color: #2aa198; font-style: italic;">"Delete an appointment when clocking a task out."</span>
  (bzg-org-clock-out-delete-appt))
</pre>
</div>

<p>
<b>IMPORTANT</b>: You can add appointment by clocking in in both an
<code>org-mode</code> and an <code>org-agenda-mode</code> buffer.  But clocking out from
agenda buffer with the advice above will bring an error.
</p>
</div>
</div>
<div id="outline-container-sec-1-9-6" class="outline-4">
<h4 id="sec-1-9-6">Using external programs for appointments reminders</h4>
<div class="outline-text-4" id="text-1-9-6">
<p>
Read this rich <a href="http://comments.gmane.org/gmane.emacs.orgmode/46641">thread</a> from the org-mode list.
</p>
</div>
</div>
<div id="outline-container-sec-1-9-7" class="outline-4">
<h4 id="sec-1-9-7">Remove from agenda time grid lines that are in an appointment</h4>
<div class="outline-text-4" id="text-1-9-7">
<p>
The agenda shows lines for the time grid.  Some people think that
these lines are a distraction when there are appointments at those
times.  You can get rid of the lines which coincide exactly with the
beginning of an appointment.  Michael Ekstrand has written a piece of
advice that also removes lines that are somewhere inside an
appointment:
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">org-time-to-minutes</span> (time)
  <span style="color: #2aa198; font-style: italic;">"Convert an HHMM time to minutes"</span>
  (<span style="color: #b58900;">+</span> (* (/ time 100) 60) (% time 100)))

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">org-time-from-minutes</span> (minutes)
  <span style="color: #2aa198; font-style: italic;">"Convert a number of minutes to an HHMM time"</span>
  (<span style="color: #b58900;">+</span> (* (/ minutes 60) 100) (% minutes 60)))

(<span style="color: #859900;">defadvice</span> <span style="color: #268bd2;">org-agenda-add-time-grid-maybe</span> (around mde-org-agenda-grid-tweakify
                                                  (list ndays todayp))
  (<span style="color: #859900;">if</span> (member 'remove-match (car org-agenda-time-grid))
      (<span style="color: #859900;">flet</span> ((extract-window
              (line)
              (<span style="color: #859900;">let</span> ((start (get-text-property 1 'time-of-day line))
                    (dur (get-text-property 1 'duration line)))
                (<span style="color: #859900;">cond</span>
                 ((<span style="color: #b58900;">and</span> start dur)
                  (cons start
                        (org-time-from-minutes
                         (<span style="color: #b58900;">+</span> dur (org-time-to-minutes start)))))
                 (start start)
                 (t <span style="color: #b58900;">nil</span>)))))
        (<span style="color: #859900;">let*</span> ((windows (delq <span style="color: #b58900;">nil</span> (mapcar 'extract-window list)))
               (org-agenda-time-grid
                (list (car org-agenda-time-grid)
                      (cadr org-agenda-time-grid)
                      (remove-if
                       (<span style="color: #b58900;">lambda</span> (time)
                         (find-if (<span style="color: #b58900;">lambda</span> (w)
                                    (<span style="color: #859900;">if</span> (numberp w)
                                        (equal w time)
                                      (<span style="color: #b58900;">and</span> (<span style="color: #b58900;">&gt;=</span> time (car w))
                                           (<span style="color: #b58900;">&lt;</span> time (cdr w)))))
                                  windows))
                       (caddr org-agenda-time-grid)))))
          ad-do-it))
    ad-do-it))
(ad-activate 'org-agenda-add-time-grid-maybe)
</pre>
</div>
</div>
</div>

<div id="outline-container-sec-1-9-8" class="outline-4">
<h4 id="sec-1-9-8">Disable version control for Org mode agenda files</h4>
<div class="outline-text-4" id="text-1-9-8">
<p>
&#x2013; David Maus
</p>

<p>
Even if you use Git to track your agenda files you might not need
vc-mode to be enabled for these files.
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(add-hook 'find-file-hook 'dmj/disable-vc-for-agenda-files-hook)
(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">dmj/disable-vc-for-agenda-files-hook</span> ()
  <span style="color: #2aa198; font-style: italic;">"Disable vc-mode for Org agenda files."</span>
  (<span style="color: #859900;">if</span> (<span style="color: #b58900;">and</span> (fboundp 'org-agenda-file-p)
           (org-agenda-file-p (buffer-file-name)))
      (remove-hook 'find-file-hook 'vc-find-file-hook)
    (add-hook 'find-file-hook 'vc-find-file-hook)))
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-1-9-9" class="outline-4">
<h4 id="sec-1-9-9">Easy customization of TODO colors</h4>
<div class="outline-text-4" id="text-1-9-9">
<p>
&#x2013; Ryan C. Thompson
</p>

<p>
Here is some code I came up with some code to make it easier to
customize the colors of various TODO keywords. As long as you just
want a different color and nothing else, you can customize the
variable org-todo-keyword-faces and use just a string color (i.e. a
string of the color name) as the face, and then org-get-todo-face
will convert the color to a face, inheriting everything else from
the standard org-todo face.
</p>

<p>
To demonstrate, I currently have org-todo-keyword-faces set to
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">((<span style="color: #2aa198;">"IN PROGRESS"</span> . <span style="color: #2aa198;">"dark orange"</span>)
 (<span style="color: #2aa198;">"WAITING"</span> . <span style="color: #2aa198;">"red4"</span>)
 (<span style="color: #2aa198;">"CANCELED"</span> . <span style="color: #2aa198;">"saddle brown"</span>))
</pre>
</div>

<p>
Here's the code, in a form you can put in your <code>.emacs</code>
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">eval-after-load</span> 'org-faces
 '(<span style="color: #859900;">progn</span>
    (<span style="color: #859900;">defcustom</span> <span style="color: #268bd2;">org-todo-keyword-faces</span> <span style="color: #b58900;">nil</span>
      <span style="color: #2aa198; font-style: italic;">"Faces for specific </span><span style="color: #cb4b16; background-color: #fdf6e3; font-style: italic;">TODO</span><span style="color: #2aa198; font-style: italic;"> keywords.</span>
<span style="color: #2aa198; font-style: italic;">This is a list of cons cells, with </span><span style="color: #cb4b16; background-color: #fdf6e3; font-style: italic;">TODO</span><span style="color: #2aa198; font-style: italic;"> keywords in the car and</span>
<span style="color: #2aa198; font-style: italic;">faces in the cdr.  The face can be a symbol, a color, or a</span>
<span style="color: #2aa198; font-style: italic;">property list of attributes, like (:foreground \"blue\" :weight</span>
<span style="color: #2aa198; font-style: italic;">bold :underline t)."</span>
      <span style="color: #657b83; font-style: italic;">:group</span> 'org-faces
      <span style="color: #657b83; font-style: italic;">:group</span> 'org-todo
      <span style="color: #657b83; font-style: italic;">:type</span> '(repeat
              (cons
               (string <span style="color: #657b83; font-style: italic;">:tag</span> <span style="color: #2aa198;">"Keyword"</span>)
               (choice color (sexp <span style="color: #657b83; font-style: italic;">:tag</span> <span style="color: #2aa198;">"Face"</span>)))))))

(<span style="color: #859900;">eval-after-load</span> 'org
 '(<span style="color: #859900;">progn</span>
    (<span style="color: #859900;">defun</span> <span style="color: #268bd2;">org-get-todo-face-from-color</span> (color)
      <span style="color: #2aa198; font-style: italic;">"Returns a specification for a face that inherits from org-todo</span>
<span style="color: #2aa198; font-style: italic;"> face and has the given color as foreground. Returns nil if</span>
<span style="color: #2aa198; font-style: italic;"> color is nil."</span>
      (<span style="color: #859900;">when</span> color
        `(<span style="color: #657b83; font-style: italic;">:inherit</span> org-warning <span style="color: #657b83; font-style: italic;">:foreground</span> ,color)))

    (<span style="color: #859900;">defun</span> <span style="color: #268bd2;">org-get-todo-face</span> (kwd)
      <span style="color: #2aa198; font-style: italic;">"Get the right face for a </span><span style="color: #cb4b16; background-color: #fdf6e3; font-style: italic;">TODO</span><span style="color: #2aa198; font-style: italic;"> keyword KWD.</span>
<span style="color: #2aa198; font-style: italic;">If KWD is a number, get the corresponding match group."</span>
      (<span style="color: #859900;">if</span> (numberp kwd) (setq kwd (match-string kwd)))
      (<span style="color: #b58900;">or</span> (<span style="color: #859900;">let</span> ((face (cdr (assoc kwd org-todo-keyword-faces))))
            (<span style="color: #859900;">if</span> (stringp face)
                (org-get-todo-face-from-color face)
              face))
          (<span style="color: #b58900;">and</span> (member kwd org-done-keywords) 'org-done)
          'org-todo))))
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-1-9-10" class="outline-4">
<h4 id="sec-1-9-10">Add an effort estimate on the fly when clocking in</h4>
<div class="outline-text-4" id="text-1-9-10">
<p>
You can use <code>org-clock-in-prepare-hook</code> to add an effort estimate.
This way you can easily have a "tea-timer" for your tasks when they
don't already have an effort estimate.
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(add-hook 'org-clock-in-prepare-hook
      'my-org-mode-ask-effort)

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">my-org-mode-ask-effort</span> ()
  <span style="color: #2aa198; font-style: italic;">"Ask for an effort estimate when clocking in."</span>
  (<span style="color: #859900;">unless</span> (org-entry-get (point) <span style="color: #2aa198;">"Effort"</span>)
    (<span style="color: #859900;">let</span> ((effort
       (completing-read
        <span style="color: #2aa198;">"Effort: "</span>
        (org-entry-get-multivalued-property (point) <span style="color: #2aa198;">"Effort"</span>))))
      (<span style="color: #859900;">unless</span> (equal effort <span style="color: #2aa198;">""</span>)
    (org-set-property <span style="color: #2aa198;">"Effort"</span> effort)))))
</pre>
</div>

<p>
Or you can use a default effort for such a timer:
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(add-hook 'org-clock-in-prepare-hook
      'my-org-mode-add-default-effort)

(<span style="color: #859900;">defvar</span> <span style="color: #268bd2;">org-clock-default-effort</span> <span style="color: #2aa198;">"1:00"</span>)

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">my-org-mode-add-default-effort</span> ()
  <span style="color: #2aa198; font-style: italic;">"Add a default effort estimation."</span>
  (<span style="color: #859900;">unless</span> (org-entry-get (point) <span style="color: #2aa198;">"Effort"</span>)
    (org-set-property <span style="color: #2aa198;">"Effort"</span> org-clock-default-effort)))
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-1-9-11" class="outline-4">
<h4 id="sec-1-9-11">Use idle timer for automatic agenda views</h4>
<div class="outline-text-4" id="text-1-9-11">
<p>
From John Wiegley's mailing list post (March 18, 2010):
</p>

<blockquote>
<p>
I have the following snippet in my .emacs file, which I find very
useful. Basically what it does is that if I don't touch my Emacs for 5
minutes, it displays the current agenda. This keeps my tasks "always
in mind" whenever I come back to Emacs after doing something else,
whereas before I had a tendency to forget that it was there.
</p>
</blockquote>

<ul class="org-ul">
<li><a href="http://mid.gmane.org/55590EA7-C744-44E5-909F-755F0BBE452D@gmail.com">John Wiegley: Displaying your Org agenda after idle time</a>
</li>
</ul>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">jump-to-org-agenda</span> ()
  (interactive)
  (<span style="color: #859900;">let</span> ((buf (get-buffer <span style="color: #2aa198;">"*Org Agenda*"</span>))
        wind)
    (<span style="color: #859900;">if</span> buf
        (<span style="color: #859900;">if</span> (setq wind (get-buffer-window buf))
            (select-window wind)
          (<span style="color: #859900;">if</span> (called-interactively-p)
              (<span style="color: #859900;">progn</span>
                (select-window (display-buffer buf t t))
                (org-fit-window-to-buffer)
                <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">(org-agenda-redo)</span>
                )
            (<span style="color: #859900;">with-selected-window</span> (display-buffer buf)
              (org-fit-window-to-buffer)
              <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">(org-agenda-redo)</span>
              )))
      (call-interactively 'org-agenda-list)))
  <span style="color: #93a1a1; font-style: italic;">;;</span><span style="color: #93a1a1;">(let ((buf (get-buffer "*Calendar*")))</span>
  <span style="color: #93a1a1; font-style: italic;">;;  </span><span style="color: #93a1a1;">(unless (get-buffer-window buf)</span>
  <span style="color: #93a1a1; font-style: italic;">;;    </span><span style="color: #93a1a1;">(org-agenda-goto-calendar)))</span>
  )

(run-with-idle-timer 300 t 'jump-to-org-agenda)
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-1-9-12" class="outline-4">
<h4 id="sec-1-9-12">Refresh the agenda view regularly</h4>
<div class="outline-text-4" id="text-1-9-12">
<p>
Hack sent by Kiwon Um:
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">kiwon/org-agenda-redo-in-other-window</span> ()
  <span style="color: #2aa198; font-style: italic;">"Call org-agenda-redo function even in the non-agenda buffer."</span>
  (interactive)
  (<span style="color: #859900;">let</span> ((agenda-window (get-buffer-window org-agenda-buffer-name t)))
    (<span style="color: #859900;">when</span> agenda-window
      (<span style="color: #859900;">with-selected-window</span> agenda-window (org-agenda-redo)))))
(run-at-time <span style="color: #b58900;">nil</span> 300 'kiwon/org-agenda-redo-in-other-window)
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-1-9-13" class="outline-4">
<h4 id="sec-1-9-13">Reschedule agenda items to today with a single command</h4>
<div class="outline-text-4" id="text-1-9-13">
<p>
This was suggested by Carsten in reply to David Abrahams:
</p>

<pre class="example">
(defun org-agenda-reschedule-to-today ()
  (interactive)
  (flet ((org-read-date (&amp;rest rest) (current-time)))
    (call-interactively 'org-agenda-schedule)))
</pre>
</div>
</div>
<div id="outline-container-sec-1-9-14" class="outline-4">
<h4 id="sec-1-9-14">Mark subtree DONE along with all subheadings</h4>
<div class="outline-text-4" id="text-1-9-14">
<p>
Bernt Hansen <a href="http://permalink.gmane.org/gmane.emacs.orgmode/44693">suggested</a> this command:
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">bh/mark-subtree-done</span> ()
  (interactive)
  (org-mark-subtree)
  (<span style="color: #859900;">let</span> ((limit (point)))
    (<span style="color: #859900;">save-excursion</span>
      (exchange-point-and-mark)
      (<span style="color: #859900;">while</span> (<span style="color: #b58900;">&gt;</span> (point) limit)
    (org-todo <span style="color: #2aa198;">"DONE"</span>)
    (outline-previous-visible-heading 1))
      (org-todo <span style="color: #2aa198;">"DONE"</span>))))
</pre>
</div>

<p>
Then M-x bh/mark-subtree-done.
</p>
</div>
</div>
<div id="outline-container-mark-done-when-all-checkboxes-checked" class="outline-4">
<h4 id="mark-done-when-all-checkboxes-checked"><a id="sec-1-9-15" name="sec-1-9-15"></a>Mark heading done when all checkboxes are checked.</h4>
<div class="outline-text-4" id="text-mark-done-when-all-checkboxes-checked">

<p>
An item consists of a list with checkboxes.  When all of the
checkboxes are checked, the item should be considered complete and its
TODO state should be automatically changed to DONE. The code below
does that. This version is slightly enhanced over the one in the
mailing list (see
<a href="http://thread.gmane.org/gmane.emacs.orgmode/42715/focus=42721">http://thread.gmane.org/gmane.emacs.orgmode/42715/focus=42721</a>) to
reset the state back to TODO if a checkbox is unchecked.
</p>

<p>
Note that the code requires that a checkbox statistics cookie (the <code>[/]</code>
or <code>[%]</code> thingie in the headline - see the <a href="http://orgmode.org/manual/Checkboxes.html#Checkboxes">Checkboxes</a> section in the
manual) be present in order for it to work. Note also that it is too
dumb to figure out whether the item has a TODO state in the first
place: if there is a statistics cookie, a TODO/DONE state will be
added willy-nilly any time that the statistics cookie is changed.
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp"><span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">see http://thread.gmane.org/gmane.emacs.orgmode/42715</span>
(<span style="color: #859900;">eval-after-load</span> 'org-list
  '(add-hook 'org-checkbox-statistics-hook (function ndk/checkbox-list-complete)))

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">ndk/checkbox-list-complete</span> ()
  (<span style="color: #859900;">save-excursion</span>
    (org-back-to-heading t)
    (<span style="color: #859900;">let</span> ((beg (point)) end)
      (end-of-line)
      (setq end (point))
      (goto-char beg)
      (<span style="color: #859900;">if</span> (re-search-forward <span style="color: #2aa198;">"\\[</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">(</span><span style="color: #2aa198;">[0-9]*%</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">)</span><span style="color: #2aa198;">\\]</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">|</span><span style="color: #2aa198;">\\[</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">(</span><span style="color: #2aa198;">[0-9]*</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">)</span><span style="color: #2aa198;">/</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">(</span><span style="color: #2aa198;">[0-9]*</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">)</span><span style="color: #2aa198;">\\]"</span> end t)
            (<span style="color: #859900;">if</span> (match-end 1)
                (<span style="color: #859900;">if</span> (equal (match-string 1) <span style="color: #2aa198;">"100%"</span>)
                    <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">all done - do the state change</span>
                    (org-todo 'done)
                  (org-todo 'todo))
              (<span style="color: #859900;">if</span> (<span style="color: #b58900;">and</span> (<span style="color: #b58900;">&gt;</span> (match-end 2) (match-beginning 2))
                       (equal (match-string 2) (match-string 3)))
                  (org-todo 'done)
                (org-todo 'todo)))))))
</pre>
</div>
</div>
</div>
<div id="outline-container-links-to-agenda-views" class="outline-4">
<h4 id="links-to-agenda-views"><a id="sec-1-9-16" name="sec-1-9-16"></a>Links to custom agenda views</h4>
<div class="outline-text-4" id="text-links-to-agenda-views">
<p>
This hack was <a href="http://lists.gnu.org/archive/html/emacs-orgmode/2012-08/msg00986.html">posted to the mailing list</a> by Nathan Neff.
</p>

<p>
If you have custom agenda commands defined to some key, say w, then
the following will serve as a link to the custom agenda buffer.
</p>
<pre class="example">
[[elisp:(org-agenda nil "w")][Show Waiting Tasks]]
</pre>

<p>
Clicking on it will prompt if you want to execute the elisp code.  If
you would rather not have the prompt or would want to respond with a
single letter, <code>y</code> or <code>n</code>, take a look at the docstrings of the
variables <code>org-confirm-elisp-link-function</code> and
<code>org-confirm-elisp-link-not-regexp</code>.  Please take special note of the
security risk associated with completely disabling the prompting
before you proceed.
</p>
</div>
</div>
</div>
<div id="outline-container-sec-1-10" class="outline-3">
<h3 id="sec-1-10">Exporting org files</h3>
<div class="outline-text-3" id="text-1-10">
</div><div id="outline-container-sec-1-10-1" class="outline-4">
<h4 id="sec-1-10-1">Export Org to Org and handle includes.</h4>
<div class="outline-text-4" id="text-1-10-1">
<p>
Nick Dokos came up with this useful function:
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">org-to-org-handle-includes</span> ()
  <span style="color: #2aa198; font-style: italic;">"Copy the contents of the current buffer to OUTFILE,</span>
<span style="color: #2aa198; font-style: italic;">recursively processing #+INCLUDEs."</span>
  (<span style="color: #859900;">let*</span> ((s (buffer-string))
     (fname (buffer-file-name))
     (ofname (format <span style="color: #2aa198;">"%s.I.org"</span> (file-name-sans-extension fname))))
    (setq result
      (<span style="color: #859900;">with-temp-buffer</span>
        (insert s)
        (org-export-handle-include-files-recurse)
        (buffer-string)))
    (find-file ofname)
    (delete-region (point-min) (point-max))
    (insert result)
    (save-buffer)))
</pre>
</div>
</div>
</div>
<div id="outline-container-latex-command-for-floats" class="outline-4">
<h4 id="latex-command-for-floats"><a id="sec-1-10-2" name="sec-1-10-2"></a>Specifying LaTeX commands to floating environments</h4>
<div class="outline-text-4" id="text-latex-command-for-floats">

<p>
The keyword <code>placement</code> can be used to specify placement options to
floating environments (like <code>\begin{figure}</code> and <code>\begin{table}</code>}) in
LaTeX export. Org passes along everything passed in options as long as
there are no spaces. One can take advantage of this to pass other
LaTeX commands and have their scope limited to the floating
environment.
</p>

<p>
For example one can set the fontsize of a table different from the
default normal size by putting something like <code>\footnotesize</code> right
after the placement options. During LaTeX export using the
<code>#+ATTR_LaTeX:</code> line below:
</p>

<div class="org-src-container">

<pre class="src src-org"><span style="color: #93a1a1;">#+ATTR_LaTeX: placement=[&lt;options&gt;]\footnotesize</span>
</pre>
</div>

<p>
exports the associated floating environment as shown in the following
block.
</p>

<div class="org-src-container">

<pre class="src src-latex"><span style="color: #586e75;">\begin</span>{<span style="color: #268bd2;">table</span>}[&lt;options&gt;]<span style="color: #586e75;">\footnotesize</span>
...
<span style="color: #586e75;">\end</span>{<span style="color: #268bd2;">table</span>}
</pre>
</div>

<p>
It should be noted that this hack does not work for beamer export of
tables since the <code>table</code> environment is not used. As an ugly
workaround, one can use the following:
</p>

<div class="org-src-container">

<pre class="src src-org"><span style="color: #93a1a1;">#+LATEX:</span> <span style="color: #93a1a1;">{\footnotesize</span>
<span style="color: #93a1a1;">#+ATTR_LaTeX: align=rr</span>
,| some | table |
,|------+-------|
,| ..   | ..    |
<span style="color: #93a1a1;">#+LATEX:</span> <span style="color: #93a1a1;">}</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-1-10-3" class="outline-4">
<h4 id="sec-1-10-3">Styling code sections with CSS</h4>
<div class="outline-text-4" id="text-1-10-3">
<p>
Code sections (marked with <code>#+begin_src</code> and <code>#+end_src</code>) are exported
to HTML using <code>&lt;pre&gt;</code> tags, and assigned CSS classes by their content
type.  For example, Perl content will have an opening tag like
<code>&lt;pre class</code>"src src-perl"&gt;=.  You can use those classes to add styling
to the output, such as here where a small language tag is added at the
top of each kind of code box:
</p>

<div class="org-src-container">

<pre class="src src-lisp">(setq org-export-html-style
 <span style="color: #2aa198;">"&lt;style type=\"text/css\"&gt;</span>
<span style="color: #2aa198;">    &lt;!--/*--&gt;&lt;![CDATA[/*&gt;&lt;!--*/</span>
<span style="color: #2aa198;">      .src             { background-color: #F5FFF5; position: relative; overflow: visible; }</span>
<span style="color: #2aa198;">      .src:before      { position: absolute; top: -15px; background: #ffffff; padding: 1px; border: 1px solid #000000; font-size: small; }</span>
<span style="color: #2aa198;">      .src-sh:before   { content: 'sh'; }</span>
<span style="color: #2aa198;">      .src-bash:before { content: 'sh'; }</span>
<span style="color: #2aa198;">      .src-R:before    { content: 'R'; }</span>
<span style="color: #2aa198;">      .src-perl:before { content: 'Perl'; }</span>
<span style="color: #2aa198;">      .src-sql:before  { content: 'SQL'; }</span>
<span style="color: #2aa198;">      .example         { background-color: #FFF5F5; }</span>
<span style="color: #2aa198;">    /*]]&gt;*/--&gt;</span>
<span style="color: #2aa198;"> &lt;/style&gt;"</span>)
</pre>
</div>

<p>
Additionally, we use color to distinguish code output (the <code>.example</code>
class) from input (all the <code>.src-*</code> classes).
</p>
</div>
</div>
</div>
<div id="outline-container-sec-1-11" class="outline-3">
<h3 id="sec-1-11">Babel</h3>
<div class="outline-text-3" id="text-1-11">
</div><div id="outline-container-sec-1-11-1" class="outline-4">
<h4 id="sec-1-11-1">How do I preview LaTeX fragments when in a LaTeX source block?</h4>
<div class="outline-text-4" id="text-1-11-1">
<p>
When editing <code>LaTeX</code> source blocks, you may want to preview LaTeX fragments
just like in an Org-mode buffer.  You can do this by using the usual
keybinding <code>C-c C-x C-l</code> after loading this snipped:
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(define-key org-src-mode-map <span style="color: #2aa198;">"\C-c\C-x\C-l"</span> 'org-edit-preview-latex-fragment)

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">org-edit-preview-latex-fragment</span> ()
  <span style="color: #2aa198; font-style: italic;">"Write latex fragment from source to parent buffer and preview it."</span>
  (interactive)
  (org-src-in-org-buffer (org-preview-latex-fragment)))
</pre>
</div>

<p>
Thanks to Sebastian Hofer for sharing this.
</p>
</div>
</div>
</div>
</div>
<div id="outline-container-sec-2" class="outline-2">
<h2 id="sec-2">Hacking Org: Working with Org-mode and other Emacs Packages.</h2>
<div class="outline-text-2" id="text-2">
</div><div id="outline-container-sec-2-1" class="outline-3">
<h3 id="sec-2-1">org-remember-anything</h3>
<div class="outline-text-3" id="text-2-1">
<p>
<a href="http://www.emacswiki.org/cgi-bin/wiki/Anything">Anything</a> users may find the snippet below interesting:
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defvar</span> <span style="color: #268bd2;">org-remember-anything</span>
  '((name . <span style="color: #2aa198;">"Org Remember"</span>)
    (candidates . (<span style="color: #b58900;">lambda</span> () (mapcar 'car org-remember-templates)))
    (action . (<span style="color: #b58900;">lambda</span> (name)
                (<span style="color: #859900;">let*</span> ((orig-template org-remember-templates)
                       (org-remember-templates
                        (list (assoc name orig-template))))
                  (call-interactively 'org-remember))))))
</pre>
</div>

<p>
You can add it to your 'anything-sources' variable and open remember directly
from anything. I imagine this would be more interesting for people with many
remember templates, so that you are out of keys to assign those to.
</p>
</div>
</div>
<div id="outline-container-sec-2-2" class="outline-3">
<h3 id="sec-2-2">Org-mode and saveplace.el</h3>
<div class="outline-text-3" id="text-2-2">
<p>
Fix a problem with <code>saveplace.el</code> putting you back in a folded position:
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(add-hook 'org-mode-hook
          (<span style="color: #b58900;">lambda</span> ()
        (<span style="color: #859900;">when</span> (outline-invisible-p)
          (<span style="color: #859900;">save-excursion</span>
        (outline-previous-visible-heading 1)
        (org-show-subtree)))))
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-2-3" class="outline-3">
<h3 id="sec-2-3">Using ido-mode for org-refile (and archiving via refile)</h3>
<div class="outline-text-3" id="text-2-3">
<p>
First set up ido-mode, for example using:
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp"><span style="color: #93a1a1; font-style: italic;">; </span><span style="color: #93a1a1;">use ido mode for completion</span>
(setq ido-everywhere t)
(setq ido-enable-flex-matching t)
(setq ido-max-directory-size 100000)
(ido-mode (quote both))
</pre>
</div>

<p>
Now to enable it in org-mode, use the following:
</p>
<div class="org-src-container">

<pre class="src src-emacs-lisp">(setq org-completion-use-ido t)
(setq org-refile-use-outline-path <span style="color: #b58900;">nil</span>)
(setq org-refile-allow-creating-parent-nodes 'confirm)
</pre>
</div>
<p>
The last line enables the creation of nodes on the fly.
</p>

<p>
If you refile into files that are not in your agenda file list, you can add them as target like this (replace file1\<sub>done</sub>, etc with your files):
</p>
<div class="org-src-container">

<pre class="src src-emacs-lisp">(setq org-refile-targets '((org-agenda-files <span style="color: #657b83; font-style: italic;">:maxlevel</span> . 5) ((<span style="color: #2aa198;">"~/org/file1_done"</span> <span style="color: #2aa198;">"~/org/file2_done"</span>) <span style="color: #657b83; font-style: italic;">:maxlevel</span> . 5) ))
</pre>
</div>

<p>
For refiling it is often not useful to include targets that have a DONE state. It's easy to remove them by using the verify-refile-target hook.
</p>
<div class="org-src-container">

<pre class="src src-emacs-lisp"><span style="color: #93a1a1; font-style: italic;">; </span><span style="color: #93a1a1;">Exclude DONE state tasks from refile targets; taken from http://doc.norang.ca/org-mode.html</span>
<span style="color: #93a1a1; font-style: italic;">; </span><span style="color: #93a1a1;">added check to only include headlines, e.g. line must have at least one child</span>
(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">my/verify-refile-target</span> ()
  <span style="color: #2aa198; font-style: italic;">"Exclude todo keywords with a DONE state from refile targets"</span>
  (<span style="color: #b58900;">or</span> (<span style="color: #b58900;">not </span>(member (nth 2 (org-heading-components)) org-done-keywords)))
      (<span style="color: #859900;">save-excursion</span> (org-goto-first-child))
  )
(setq org-refile-target-verify-function 'my/verify-refile-target)
</pre>
</div>
<p>
Now when looking for a refile target, you can use the full power of ido to find them. Ctrl-R can be used to switch between different options that ido offers.
</p>
</div>
</div>
<div id="outline-container-sec-2-4" class="outline-3">
<h3 id="sec-2-4">Using ido-completing-read to find attachments</h3>
<div class="outline-text-3" id="text-2-4">
<p>
&#x2013; Matt Lundin.
</p>

<p>
Org-attach is great for quickly linking files to a project. But if you
use org-attach extensively you might find yourself wanting to browse
all the files you've attached to org headlines. This is not easy to do
manually, since the directories containing the files are not human
readable (i.e., they are based on automatically generated ids). Here's
some code to browse those files using ido (obviously, you need to be
using ido):
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(load-library <span style="color: #2aa198;">"find-lisp"</span>)

<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">Adapted from http://www.emacswiki.org/emacs/RecentFiles</span>

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">my-ido-find-org-attach</span> ()
  <span style="color: #2aa198; font-style: italic;">"Find files in org-attachment directory"</span>
  (interactive)
  (<span style="color: #859900;">let*</span> ((enable-recursive-minibuffers t)
         (files (find-lisp-find-files org-attach-directory <span style="color: #2aa198;">"."</span>))
         (file-assoc-list
          (mapcar (<span style="color: #b58900;">lambda</span> (x)
                    (cons (file-name-nondirectory x)
                          x))
                  files))
         (filename-list
          (remove-duplicates (mapcar #'car file-assoc-list)
                             <span style="color: #657b83; font-style: italic;">:test</span> #'string=))
         (filename (ido-completing-read <span style="color: #2aa198;">"Org attachments: "</span> filename-list <span style="color: #b58900;">nil</span> t))
         (longname (cdr (assoc filename file-assoc-list))))
    (ido-set-current-directory
     (<span style="color: #859900;">if</span> (file-directory-p longname)
         longname
       (file-name-directory longname)))
    (setq ido-exit 'refresh
          ido-text-init ido-text
          ido-rotate-temp t)
    (exit-minibuffer)))

(add-hook 'ido-setup-hook 'ido-my-keys)

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">ido-my-keys</span> ()
  <span style="color: #2aa198; font-style: italic;">"Add my keybindings for ido."</span>
  (define-key ido-completion-map (kbd <span style="color: #2aa198;">"C-;"</span>) 'my-ido-find-org-attach))
</pre>
</div>

<p>
To browse your org attachments using ido fuzzy matching and/or the
completion buffer, invoke ido-find-file as usual (<code>C-x C-f</code>) and then
press <code>C-;</code>.
</p>
</div>
</div>
<div id="outline-container-sec-2-5" class="outline-3">
<h3 id="sec-2-5">Link to Gnus messages by Message-Id</h3>
<div class="outline-text-3" id="text-2-5">
<p>
In a <a href="http://thread.gmane.org/gmane.emacs.orgmode/8860">recent thread</a> on the Org-Mode mailing list, there was some
discussion about linking to Gnus messages without encoding the folder
name in the link.  The following code hooks in to the store-link
function in Gnus to capture links by Message-Id when in nnml folders,
and then provides a link type "mid" which can open this link.  The
<code>mde-org-gnus-open-message-link</code> function uses the
<code>mde-mid-resolve-methods</code> variable to determine what Gnus backends to
scan.  It will go through them, in order, asking each to locate the
message and opening it from the first one that reports success.
</p>

<p>
It has only been tested with a single nnml backend, so there may be
bugs lurking here and there.
</p>

<p>
The logic for finding the message was adapted from <a href="http://www.emacswiki.org/cgi-bin/wiki/FindMailByMessageId">an Emacs Wiki
article</a>.
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp"><span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">Support for saving Gnus messages by Message-ID</span>
(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">mde-org-gnus-save-by-mid</span> ()
  (<span style="color: #859900;">when</span> (memq major-mode '(gnus-summary-mode gnus-article-mode))
    (<span style="color: #859900;">when</span> (eq major-mode 'gnus-article-mode)
      (gnus-article-show-summary))
    (<span style="color: #859900;">let*</span> ((group gnus-newsgroup-name)
           (method (gnus-find-method-for-group group)))
      (<span style="color: #859900;">when</span> (eq 'nnml (car method))
        (<span style="color: #859900;">let*</span> ((article (gnus-summary-article-number))
               (header (gnus-summary-article-header article))
               (from (mail-header-from header))
               (message-id
                (<span style="color: #859900;">save-match-data</span>
                  (<span style="color: #859900;">let</span> ((mid (mail-header-id header)))
                    (<span style="color: #859900;">if</span> (string-match <span style="color: #2aa198;">"&lt;</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">(</span><span style="color: #2aa198;">.*</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">)</span><span style="color: #2aa198;">&gt;"</span> mid)
                        (match-string 1 mid)
                      (<span style="color: #cb4b16; font-weight: bold; text-decoration: underline;">error</span> <span style="color: #2aa198;">"Malformed message ID header %s"</span> mid)))))
               (date (mail-header-date header))
               (subject (gnus-summary-subject-string)))
          (org-store-link-props <span style="color: #657b83; font-style: italic;">:type</span> <span style="color: #2aa198;">"mid"</span> <span style="color: #657b83; font-style: italic;">:from</span> from <span style="color: #657b83; font-style: italic;">:subject</span> subject
                                <span style="color: #657b83; font-style: italic;">:message-id</span> message-id <span style="color: #657b83; font-style: italic;">:group</span> group
                                <span style="color: #657b83; font-style: italic;">:link</span> (org-make-link <span style="color: #2aa198;">"mid:"</span> message-id))
          (apply 'org-store-link-props
                 <span style="color: #657b83; font-style: italic;">:description</span> (org-email-link-description)
                 org-store-link-plist)
          t)))))

(<span style="color: #859900;">defvar</span> <span style="color: #268bd2;">mde-mid-resolve-methods</span> '()
  <span style="color: #2aa198; font-style: italic;">"List of methods to try when resolving message ID's.  For Gnus,</span>
<span style="color: #2aa198; font-style: italic;">it is a cons of 'gnus and the select (type and name)."</span>)
(setq mde-mid-resolve-methods
      '((gnus nnml <span style="color: #2aa198;">""</span>)))

(<span style="color: #859900;">defvar</span> <span style="color: #268bd2;">mde-org-gnus-open-level</span> 1
  <span style="color: #2aa198; font-style: italic;">"Level at which Gnus is started when opening a link"</span>)
(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">mde-org-gnus-open-message-link</span> (msgid)
  <span style="color: #2aa198; font-style: italic;">"Open a message link with Gnus"</span>
  (<span style="color: #859900;">require</span> '<span style="color: #268bd2; font-weight: bold;">gnus</span>)
  (<span style="color: #859900;">require</span> '<span style="color: #268bd2; font-weight: bold;">org-table</span>)
  (<span style="color: #859900;">catch</span> '<span style="color: #268bd2; font-weight: bold;">method-found</span>
    (message <span style="color: #2aa198;">"[MID linker] Resolving %s"</span> msgid)
    (<span style="color: #859900;">dolist</span> (method mde-mid-resolve-methods)
      (<span style="color: #859900;">cond</span>
       ((<span style="color: #b58900;">and</span> (eq (car method) 'gnus)
             (eq (cadr method) 'nnml))
        (funcall (cdr (assq 'gnus org-link-frame-setup))
                 mde-org-gnus-open-level)
        (<span style="color: #859900;">when</span> gnus-other-frame-object
          (select-frame gnus-other-frame-object))
        (<span style="color: #859900;">let*</span> ((msg-info (nnml-find-group-number
                          (concat <span style="color: #2aa198;">"&lt;"</span> msgid <span style="color: #2aa198;">"&gt;"</span>)
                          (cdr method)))
               (group (<span style="color: #b58900;">and</span> msg-info (car msg-info)))
               (message (<span style="color: #b58900;">and</span> msg-info (cdr msg-info)))
               (qname (<span style="color: #b58900;">and</span> group
                           (<span style="color: #859900;">if</span> (gnus-methods-equal-p
                                (cdr method)
                                gnus-select-method)
                               group
                             (gnus-group-full-name group (cdr method))))))
          (<span style="color: #859900;">when</span> msg-info
            (gnus-summary-read-group qname <span style="color: #b58900;">nil</span> t)
            (gnus-summary-goto-article message <span style="color: #b58900;">nil</span> t))
          (<span style="color: #859900;">throw</span> '<span style="color: #268bd2; font-weight: bold;">method-found</span> t)))
       (t (<span style="color: #cb4b16; font-weight: bold; text-decoration: underline;">error</span> <span style="color: #2aa198;">"Unknown link type"</span>))))))

(<span style="color: #859900;">eval-after-load</span> 'org-gnus
  '(<span style="color: #859900;">progn</span>
     (add-to-list 'org-store-link-functions 'mde-org-gnus-save-by-mid)
     (org-add-link-type <span style="color: #2aa198;">"mid"</span> 'mde-org-gnus-open-message-link)))
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-2-6" class="outline-3">
<h3 id="sec-2-6">Store link to a message when sending in Gnus</h3>
<div class="outline-text-3" id="text-2-6">
<p>
Ulf Stegemann came up with this solution (see his <a href="http://www.mail-archive.com/emacs-orgmode@gnu.org/msg33278.html">original message</a>):
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">ulf-message-send-and-org-gnus-store-link</span> (<span style="color: #b58900;">&amp;optional</span> arg)
  <span style="color: #2aa198; font-style: italic;">"Send message with `</span><span style="color: #2aa198; font-weight: bold; font-style: italic;">message-send-and-exit</span><span style="color: #2aa198; font-style: italic;">' and store org link to message copy.</span>
<span style="color: #2aa198; font-style: italic;">If multiple groups appear in the Gcc header, the link refers to</span>
<span style="color: #2aa198; font-style: italic;">the copy in the last group."</span>
  (interactive <span style="color: #2aa198;">"P"</span>)
    (<span style="color: #859900;">save-excursion</span>
      (<span style="color: #859900;">save-restriction</span>
    (message-narrow-to-headers)
    (<span style="color: #859900;">let</span> ((gcc (car (last
             (message-unquote-tokens
              (message-tokenize-header
               (mail-fetch-field <span style="color: #2aa198;">"gcc"</span> <span style="color: #b58900;">nil</span> t) <span style="color: #2aa198;">" ,"</span>)))))
          (buf (current-buffer))
          (message-kill-buffer-on-exit <span style="color: #b58900;">nil</span>)
          id to from subject desc link newsgroup xarchive)
        (message-send-and-exit arg)
        (<span style="color: #b58900;">or</span>
         <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">gcc group found ...</span>
         (<span style="color: #b58900;">and</span> gcc
              (<span style="color: #859900;">save-current-buffer</span>
                (<span style="color: #859900;">progn</span> (set-buffer buf)
                       (setq id (org-remove-angle-brackets
                                 (mail-fetch-field <span style="color: #2aa198;">"Message-ID"</span>)))
                       (setq to (mail-fetch-field <span style="color: #2aa198;">"To"</span>))
                       (setq from (mail-fetch-field <span style="color: #2aa198;">"From"</span>))
                       (setq subject (mail-fetch-field <span style="color: #2aa198;">"Subject"</span>))))
              (org-store-link-props <span style="color: #657b83; font-style: italic;">:type</span> <span style="color: #2aa198;">"gnus"</span> <span style="color: #657b83; font-style: italic;">:from</span> from <span style="color: #657b83; font-style: italic;">:subject</span> subject
                                    <span style="color: #657b83; font-style: italic;">:message-id</span> id <span style="color: #657b83; font-style: italic;">:group</span> gcc <span style="color: #657b83; font-style: italic;">:to</span> to)
              (setq desc (org-email-link-description))
              (setq link (org-gnus-article-link
                          gcc newsgroup id xarchive))
              (setq org-stored-links
                    (cons (list link desc) org-stored-links)))
         <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">no gcc group found ...</span>
         (message <span style="color: #2aa198;">"Can not create Org link: No Gcc header found."</span>))))))

(define-key message-mode-map [(control c) (control meta c)]
  'ulf-message-send-and-org-gnus-store-link)
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-2-7" class="outline-3">
<h3 id="sec-2-7">Send html messages and attachments with Wanderlust</h3>
<div class="outline-text-3" id="text-2-7">
<p>
&#x2013; David Maus
</p>

<p>
<i>Note</i>: The module <a href="org-contrib/org-mime.html">Org-mime</a> in Org's contrib directory provides
similar functionality for both Wanderlust and Gnus.  The hack below is
still somewhat different: It allows you to toggle sending of html
messages within Wanderlust transparently.  I.e. html markup of the
message body is created right before sending starts.
</p>
</div>

<div id="outline-container-sec-2-7-1" class="outline-4">
<h4 id="sec-2-7-1">Send HTML message</h4>
<div class="outline-text-4" id="text-2-7-1">
<p>
Putting the code below in your .emacs adds following four functions:
</p>

<ul class="org-ul">
<li>dmj/wl-send-html-message

<p>
Function that does the job: Convert everything between "&#x2013;text
follows this line&#x2013;" and first mime entity (read: attachment) or
end of buffer into html markup using `org-export-region-as-html'
and replaces original body with a multipart MIME entity with the
plain text version of body and the html markup version.  Thus a
recipient that prefers html messages can see the html markup,
recipients that prefer or depend on plain text can see the plain
text.
</p>

<p>
Cannot be called interactively: It is hooked into SEMI's
`mime-edit-translate-hook' if message should be HTML message.
</p>
</li>

<li>dmj/wl-send-html-message-draft-init

<p>
Cannot be called interactively: It is hooked into WL's
`wl-mail-setup-hook' and provides a buffer local variable to
toggle.
</p>
</li>

<li>dmj/wl-send-html-message-draft-maybe

<p>
Cannot be called interactively: It is hooked into WL's
`wl-draft-send-hook' and hooks `dmj/wl-send-html-message' into
`mime-edit-translate-hook' depending on whether HTML message is
toggled on or off
</p>
</li>

<li>dmj/wl-send-html-message-toggle

<p>
Toggles sending of HTML message.  If toggled on, the letters
"HTML" appear in the mode line.
</p>

<p>
Call it interactively!  Or bind it to a key in `wl-draft-mode'.
</p>
</li>
</ul>

<p>
If you have to send HTML messages regularly you can set a global
variable `dmj/wl-send-html-message-toggled-p' to the string "HTML" to
toggle on sending HTML message by default.
</p>

<p>
The image <a href="http://s11.directupload.net/file/u/15851/48ru5wl3.png">here</a> shows an example of how the HTML message looks like in
Google's web front end.  As you can see you have the whole markup of
Org at your service: <b>bold</b>, <i>italics</i>, tables, lists&#x2026;
</p>

<p>
So even if you feel uncomfortable with sending HTML messages at least
you send HTML that looks quite good.
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">dmj/wl-send-html-message</span> ()
  <span style="color: #2aa198; font-style: italic;">"Send message as html message.</span>
<span style="color: #2aa198; font-style: italic;">Convert body of message to html using</span>
<span style="color: #2aa198; font-style: italic;">  `</span><span style="color: #2aa198; font-weight: bold; font-style: italic;">org-export-region-as-html</span><span style="color: #2aa198; font-style: italic;">'."</span>
  (<span style="color: #859900;">require</span> '<span style="color: #268bd2; font-weight: bold;">org</span>)
  (<span style="color: #859900;">save-excursion</span>
    (<span style="color: #859900;">let</span> (beg end html text)
      (goto-char (point-min))
      (re-search-forward <span style="color: #2aa198;">"^--text follows this line--$"</span>)
      <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">move to beginning of next line</span>
      (beginning-of-line 2)
      (setq beg (point))
      (<span style="color: #859900;">if</span> (<span style="color: #b58900;">not </span>(re-search-forward <span style="color: #2aa198;">"^--\\[\\["</span> <span style="color: #b58900;">nil</span> t))
          (setq end (point-max))
        <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">line up</span>
        (end-of-line 0)
        (setq end (point)))
      <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">grab body</span>
      (setq text (buffer-substring-no-properties beg end))
      <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">convert to html</span>
      (<span style="color: #859900;">with-temp-buffer</span>
        (org-mode)
        (insert text)
        <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">handle signature</span>
        (<span style="color: #859900;">when</span> (re-search-backward <span style="color: #2aa198;">"^-- \n"</span> <span style="color: #b58900;">nil</span> t)
          <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">preserve link breaks in signature</span>
          (insert <span style="color: #2aa198;">"\n#+BEGIN_VERSE\n"</span>)
          (goto-char (point-max))
          (insert <span style="color: #2aa198;">"\n#+END_VERSE\n"</span>)
          <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">grab html</span>
          (setq html (org-export-region-as-html
                      (point-min) (point-max) t 'string))))
      (delete-region beg end)
      (insert
       (concat
        <span style="color: #2aa198;">"--"</span> <span style="color: #2aa198;">"&lt;&lt;alternative&gt;&gt;-{\n"</span>
        <span style="color: #2aa198;">"--"</span> <span style="color: #2aa198;">"[[text/plain]]\n"</span> text
        <span style="color: #2aa198;">"--"</span> <span style="color: #2aa198;">"[[text/html]]\n"</span>  html
        <span style="color: #2aa198;">"--"</span> <span style="color: #2aa198;">"}-&lt;&lt;alternative&gt;&gt;\n"</span>)))))

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">dmj/wl-send-html-message-toggle</span> ()
  <span style="color: #2aa198; font-style: italic;">"Toggle sending of html message."</span>
  (interactive)
  (setq dmj/wl-send-html-message-toggled-p
        (<span style="color: #859900;">if</span> dmj/wl-send-html-message-toggled-p
            <span style="color: #b58900;">nil</span> <span style="color: #2aa198;">"HTML"</span>))
  (message <span style="color: #2aa198;">"Sending html message toggled %s"</span>
           (<span style="color: #859900;">if</span> dmj/wl-send-html-message-toggled-p
               <span style="color: #2aa198;">"on"</span> <span style="color: #2aa198;">"off"</span>)))

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">dmj/wl-send-html-message-draft-init</span> ()
  <span style="color: #2aa198; font-style: italic;">"Create buffer local settings for maybe sending html message."</span>
  (<span style="color: #859900;">unless</span> (boundp 'dmj/wl-send-html-message-toggled-p)
    (setq dmj/wl-send-html-message-toggled-p <span style="color: #b58900;">nil</span>))
  (make-variable-buffer-local 'dmj/wl-send-html-message-toggled-p)
  (add-to-list 'global-mode-string
               '(<span style="color: #657b83; font-style: italic;">:eval</span> (<span style="color: #859900;">if</span> (eq major-mode 'wl-draft-mode)
                           dmj/wl-send-html-message-toggled-p))))

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">dmj/wl-send-html-message-maybe</span> ()
  <span style="color: #2aa198; font-style: italic;">"Maybe send this message as html message.</span>

<span style="color: #2aa198; font-style: italic;">If buffer local variable `</span><span style="color: #2aa198; font-weight: bold; font-style: italic;">dmj/wl-send-html-message-toggled-p</span><span style="color: #2aa198; font-style: italic;">' is</span>
<span style="color: #2aa198; font-style: italic;">non-nil, add `</span><span style="color: #2aa198; font-weight: bold; font-style: italic;">dmj/wl-send-html-message</span><span style="color: #2aa198; font-style: italic;">' to</span>
<span style="color: #2aa198; font-style: italic;">`</span><span style="color: #2aa198; font-weight: bold; font-style: italic;">mime-edit-translate-hook</span><span style="color: #2aa198; font-style: italic;">'."</span>
  (<span style="color: #859900;">if</span> dmj/wl-send-html-message-toggled-p
      (add-hook 'mime-edit-translate-hook 'dmj/wl-send-html-message)
    (remove-hook 'mime-edit-translate-hook 'dmj/wl-send-html-message)))

(add-hook 'wl-draft-reedit-hook 'dmj/wl-send-html-message-draft-init)
(add-hook 'wl-mail-setup-hook 'dmj/wl-send-html-message-draft-init)
(add-hook 'wl-draft-send-hook 'dmj/wl-send-html-message-maybe)
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-2-7-2" class="outline-4">
<h4 id="sec-2-7-2">Attach HTML of region or subtree</h4>
<div class="outline-text-4" id="text-2-7-2">
<p>
Instead of sending a complete HTML message you might only send parts
of an Org file as HTML for the poor souls who are plagued with
non-proportional fonts in their mail program that messes up pretty
ASCII tables.
</p>

<p>
This short function does the trick: It exports region or subtree to
HTML, prefixes it with a MIME entity delimiter and pushes to killring
and clipboard.  If a region is active, it uses the region, the
complete subtree otherwise.
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">dmj/org-export-region-as-html-attachment</span> (beg end arg)
  <span style="color: #2aa198; font-style: italic;">"Export region between BEG and END as html attachment.</span>
<span style="color: #2aa198; font-style: italic;">If BEG and END are not set, use current subtree.  Region or</span>
<span style="color: #2aa198; font-style: italic;">subtree is exported to html without header and footer, prefixed</span>
<span style="color: #2aa198; font-style: italic;">with a mime entity string and pushed to clipboard and killring.</span>
<span style="color: #2aa198; font-style: italic;">When called with prefix, mime entity is not marked as</span>
<span style="color: #2aa198; font-style: italic;">attachment."</span>
  (interactive <span style="color: #2aa198;">"r\nP"</span>)
  (<span style="color: #859900;">save-excursion</span>
    (<span style="color: #859900;">let*</span> ((beg (<span style="color: #859900;">if</span> (region-active-p) (region-beginning)
                  (<span style="color: #859900;">progn</span>
                    (org-back-to-heading)
                    (point))))
           (end (<span style="color: #859900;">if</span> (region-active-p) (region-end)
                  (<span style="color: #859900;">progn</span>
                    (org-end-of-subtree)
                    (point))))
           (html (concat <span style="color: #2aa198;">"--[[text/html"</span>
                         (<span style="color: #859900;">if</span> arg <span style="color: #2aa198;">""</span> <span style="color: #2aa198;">"\nContent-Disposition: attachment"</span>)
                         <span style="color: #2aa198;">"]]\n"</span>
                         (org-export-region-as-html beg end t 'string))))
      (<span style="color: #859900;">when</span> (fboundp 'x-set-selection)
        (<span style="color: #859900;">ignore-errors</span> (x-set-selection 'PRIMARY html))
        (<span style="color: #859900;">ignore-errors</span> (x-set-selection 'CLIPBOARD html)))
      (message <span style="color: #2aa198;">"html export done, pushed to kill ring and clipboard"</span>))))
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-2-7-3" class="outline-4">
<h4 id="sec-2-7-3">Adopting for Gnus</h4>
<div class="outline-text-4" id="text-2-7-3">
<p>
The whole magic lies in the special strings that mark a HTML
attachment.  So you might just have to find out what these special
strings are in message-mode and modify the functions accordingly.
</p>
</div>
</div>
</div>

<div id="outline-container-sec-2-8" class="outline-3">
<h3 id="sec-2-8">Add sunrise/sunset times to the agenda.</h3>
<div class="outline-text-3" id="text-2-8">
<p>
&#x2013; Nick Dokos
</p>

<p>
The diary package provides the function <code>diary-sunrise-sunset</code> which can be used
in a diary s-expression in some agenda file like this:
</p>

<div class="org-src-container">

<pre class="src src-org-mode">%%(diary-sunrise-sunset)
</pre>
</div>

<p>
Seb Vauban asked if it is possible to put sunrise and sunset in
separate lines. Here is a hack to do that. It adds two functions (they
have to be available before the agenda is shown, so I add them early
in my org-config file which is sourced from .emacs, but you'll have to
suit yourself here) that just parse the output of
diary-sunrise-sunset, instead of doing the right thing which would be
to take advantage of the data structures that diary/solar.el provides.
In short, a hack - so perfectly suited for inclusion here :-)
</p>

<p>
The functions (and latitude/longitude settings which you have to modify for
your location) are as follows:
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(setq calendar-latitude 48.2)
(setq calendar-longitude 16.4)
(setq calendar-location-name <span style="color: #2aa198;">"Vienna, Austria"</span>)

(autoload 'solar-sunrise-sunset <span style="color: #2aa198;">"solar.el"</span>)
(autoload 'solar-time-string <span style="color: #2aa198;">"solar.el"</span>)
(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">diary-sunrise</span> ()
  <span style="color: #2aa198; font-style: italic;">"Local time of sunrise as a diary entry.</span>
<span style="color: #2aa198; font-style: italic;">The diary entry can contain `</span><span style="color: #2aa198; font-weight: bold; font-style: italic;">%s</span><span style="color: #2aa198; font-style: italic;">' which will be replaced with</span>
<span style="color: #2aa198; font-style: italic;">`</span><span style="color: #2aa198; font-weight: bold; font-style: italic;">calendar-location-name</span><span style="color: #2aa198; font-style: italic;">'."</span>
  (<span style="color: #859900;">let</span> ((l (solar-sunrise-sunset date)))
    (<span style="color: #859900;">when</span> (car l)
      (concat
       (<span style="color: #859900;">if</span> (string= entry <span style="color: #2aa198;">""</span>)
           <span style="color: #2aa198;">"Sunrise"</span>
         (format entry (eval calendar-location-name))) <span style="color: #2aa198;">" "</span>
         (solar-time-string (caar l) <span style="color: #b58900;">nil</span>)))))

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">diary-sunset</span> ()
  <span style="color: #2aa198; font-style: italic;">"Local time of sunset as a diary entry.</span>
<span style="color: #2aa198; font-style: italic;">The diary entry can contain `</span><span style="color: #2aa198; font-weight: bold; font-style: italic;">%s</span><span style="color: #2aa198; font-style: italic;">' which will be replaced with</span>
<span style="color: #2aa198; font-style: italic;">`</span><span style="color: #2aa198; font-weight: bold; font-style: italic;">calendar-location-name</span><span style="color: #2aa198; font-style: italic;">'."</span>
  (<span style="color: #859900;">let</span> ((l (solar-sunrise-sunset date)))
    (<span style="color: #859900;">when</span> (cadr l)
      (concat
       (<span style="color: #859900;">if</span> (string= entry <span style="color: #2aa198;">""</span>)
           <span style="color: #2aa198;">"Sunset"</span>
         (format entry (eval calendar-location-name))) <span style="color: #2aa198;">" "</span>
         (solar-time-string (caadr l) <span style="color: #b58900;">nil</span>)))))
</pre>
</div>

<p>
You also need to add a couple of diary s-expressions in one of your agenda
files:
</p>

<div class="org-src-container">

<pre class="src src-org-mode">%%(diary-sunrise)Sunrise in %s
%%(diary-sunset)
</pre>
</div>

<p>
This will show sunrise with the location and sunset without it.
</p>

<p>
The thread on the mailing list that started this can be found <a href="http://thread.gmane.org/gmane.emacs.orgmode/38723Here%20is%20a%20pointer%20to%20the%20thread%20on%20the%20mailing%20list">here</a>.
In comparison to the version posted on the mailing list, this one
gets rid of the timezone information and can show the location.
</p>
</div>
</div>

<div id="outline-container-sec-2-9" class="outline-3">
<h3 id="sec-2-9">Add lunar phases to the agenda.</h3>
<div class="outline-text-3" id="text-2-9">
<p>
&#x2013; Rüdiger
</p>

<p>
Emacs comes with <code>lunar.el</code> to display the lunar phases (<code>M-x lunar-phases</code>).
This can be used to display lunar phases in the agenda display with the
following function:
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">require</span> '<span style="color: #268bd2; font-weight: bold;">cl-lib</span>)

(org-no-warnings (<span style="color: #859900;">defvar</span> <span style="color: #268bd2;">date</span>))
(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">org-lunar-phases</span> ()
  <span style="color: #2aa198; font-style: italic;">"Show lunar phase in Agenda buffer."</span>
  (<span style="color: #859900;">require</span> '<span style="color: #268bd2; font-weight: bold;">lunar</span>)
  (<span style="color: #859900;">let*</span> ((phase-list (lunar-phase-list (nth 0 date) (nth 2 date)))
         (phase (cl-find-if (<span style="color: #b58900;">lambda</span> (phase) (equal (car phase) date))
                            phase-list)))
    (<span style="color: #859900;">when</span> phase
      (setq ret (concat (lunar-phase-name (nth 2 phase)) <span style="color: #2aa198;">" "</span>
                        (substring (nth 1 phase) 0 5))))))
</pre>
</div>

<p>
Add the following line to an agenda file:
</p>

<p>
#+begin<sub>src</sub> org-mode
</p>
</div>
</div>
</div>

<div id="outline-container-sec-3" class="outline-2">
<h2 id="sec-3">Lunar phase</h2>
<div class="outline-text-2" id="text-3">
<p>
#+end<sub>src</sub>
</p>

<p>
This should display an entry on new moon, first/last quarter moon, and on full
moon.  You can customize the entries by customizing <code>lunar-phase-names</code>.
</p>

<p>
E.g., to add Unicode symbols:
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(setq lunar-phase-names
      '(<span style="color: #2aa198;">"&#9679; New Moon"</span> <span style="color: #93a1a1; font-style: italic;">; </span><span style="color: #93a1a1;">Unicode symbol: &#127761; Use full circle as fallback</span>
        <span style="color: #2aa198;">"&#9789; First Quarter Moon"</span>
        <span style="color: #2aa198;">"&#9675; Full Moon"</span> <span style="color: #93a1a1; font-style: italic;">; </span><span style="color: #93a1a1;">Unicode symbol: &#127765; Use empty circle as fallback</span>
        <span style="color: #2aa198;">"&#9790; Last Quarter Moon"</span>))
</pre>
</div>

<p>
Unicode 6 even provides symbols for the Moon with nice faces.  But those
symbols are currently barely supported in fonts.
See <a href="https://en.wikipedia.org/wiki/Astronomical_symbols#Moon">Astronomical symbols on Wikipedia</a>.
</p>
</div>

<div id="outline-container-sec-3-1" class="outline-3">
<h3 id="sec-3-1">Export BBDB contacts to org-contacts.el</h3>
<div class="outline-text-3" id="text-3-1">
<p>
Try this tool by Wes Hardaker:
</p>

<p>
<a href="http://www.hardakers.net/code/bbdb-to-org-contacts/">http://www.hardakers.net/code/bbdb-to-org-contacts/</a>
</p>
</div>
</div>
<div id="outline-container-sec-3-2" class="outline-3">
<h3 id="sec-3-2">Calculating date differences - how to write a simple elisp function</h3>
<div class="outline-text-3" id="text-3-2">
<p>
Alexander Wingård asked how to calculate the number of days between a
time stamp in his org file and today (see
<a href="http://thread.gmane.org/gmane.emacs.orgmode/46881">http://thread.gmane.org/gmane.emacs.orgmode/46881</a>).  Although the
resulting answer is probably not of general interest, the method might
be useful to a budding Elisp programmer.
</p>

<p>
Alexander started from an already existing org function,
<code>org-evaluate-time-range</code>.  When this function is called in the context
of a time range (two time stamps separated by "<code>--</code>"), it calculates the
number of days between the two dates and outputs the result in Emacs's
echo area. What he wanted was a similar function that, when called from
the context of a single time stamp, would calculate the number of days
between the date in the time stamp and today. The result should go to
the same place: Emacs's echo area.
</p>

<p>
The solution presented in the mail thread is as follows:
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">aw/org-evaluate-time-range</span> (<span style="color: #b58900;">&amp;optional</span> to-buffer)
  (interactive)
  (<span style="color: #859900;">if</span> (org-at-date-range-p t)
      (org-evaluate-time-range to-buffer)
    <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">otherwise, make a time range in a temp buffer and run o-e-t-r there</span>
    (<span style="color: #859900;">let</span> ((headline (buffer-substring (point-at-bol) (point-at-eol))))
      (<span style="color: #859900;">with-temp-buffer</span>
    (insert headline)
    (goto-char (point-at-bol))
    (re-search-forward org-ts-regexp (point-at-eol) t)
    (<span style="color: #859900;">if</span> (<span style="color: #b58900;">not </span>(org-at-timestamp-p t))
        (<span style="color: #cb4b16; font-weight: bold; text-decoration: underline;">error</span> <span style="color: #2aa198;">"No timestamp here"</span>))
    (goto-char (match-beginning 0))
    (org-insert-time-stamp (current-time) <span style="color: #b58900;">nil</span> <span style="color: #b58900;">nil</span>)
    (insert <span style="color: #2aa198;">"--"</span>)
    (org-evaluate-time-range to-buffer)))))
</pre>
</div>

<p>
The function assumes that point is on some line with some time stamp
(or a date range) in it. Note that <code>org-evaluate-time-range</code> does not care
whether the first date is earlier than the second: it will always output
the number of days between the earlier date and the later date.
</p>

<p>
As stated before, the function itself is of limited interest (although
it satisfied Alexander's need).The <b>method</b> used might be of wider
interest however, so here is a short explanation.
</p>

<p>
The idea is that we want <code>org-evaluate-time-range</code> to do all the
heavy lifting, but that function requires that it be in a date-range
context. So the function first checks whether it's in a date range
context already: if so, it calls <code>org-evaluate-time-range</code> directly
to do the work. The trick now is to arrange things so we can call this
same function in the case where we do <b>not</b> have a date range
context. In that case, we manufacture one: we create a temporary
buffer, copy the line with the purported time stamp to the temp
buffer, find the time stamp (signal an error if no time stamp is
found) and insert a new time stamp with the current time before the
existing time stamp, followed by "<code>--</code>": voilà, we now have a time range
on which we can apply our old friend <code>org-evaluate-time-range</code> to
produce the answer. Because of the above-mentioned property
of <code>org-evaluate-time-range</code>, it does not matter if the existing
time stamp is earlier or later than the current time: the correct
number of days is output.
</p>

<p>
Note that at the end of the call to <code>with-temp-buffer</code>, the temporary
buffer goes away.  It was just used as a scratch pad for the function
to do some figuring.
</p>

<p>
The idea of using a temp buffer as a scratch pad has wide
applicability in Emacs programming. The rest of the work is knowing
enough about facilities provided by Emacs (e.g. regexp searching) and
by Org (e.g. checking for time stamps and generating a time stamp) so
that you don't reinvent the wheel, and impedance-matching between the
various pieces.
</p>
</div>
</div>
<div id="outline-container-sec-3-3" class="outline-3">
<h3 id="sec-3-3">ibuffer and org files</h3>
<div class="outline-text-3" id="text-3-3">
<p>
Neil Smithline posted this snippet to let you browse org files with
<code>ibuffer</code>:
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">require</span> '<span style="color: #268bd2; font-weight: bold;">ibuffer</span>)

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">org-ibuffer</span> ()
  <span style="color: #2aa198; font-style: italic;">"Open an `</span><span style="color: #2aa198; font-weight: bold; font-style: italic;">ibuffer</span><span style="color: #2aa198; font-style: italic;">' window showing only `</span><span style="color: #2aa198; font-weight: bold; font-style: italic;">org-mode</span><span style="color: #2aa198; font-style: italic;">' buffers."</span>
  (interactive)
  (ibuffer <span style="color: #b58900;">nil</span> <span style="color: #2aa198;">"*Org Buffers*"</span> '((used-mode . org-mode))))
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-3-4" class="outline-3">
<h3 id="sec-3-4">Enable org-mode links in other modes</h3>
<div class="outline-text-3" id="text-3-4">
<p>
Sean O'Halpin wrote a minor mode for this, please check it <a href="https://github.com/seanohalpin/org-link-minor-mode">here</a>.
</p>

<p>
See the relevant discussion <a href="http://thread.gmane.org/gmane.emacs.orgmode/58715/focus%3D58794">here</a>.
</p>
</div>
</div>
<div id="outline-container-sec-3-5" class="outline-3">
<h3 id="sec-3-5">poporg.el: edit comments in org-mode</h3>
<div class="outline-text-3" id="text-3-5">
<p>
<a href="https://github.com/pinard/PopOrg/blob/master/poporg.el">poporg.el</a> is a library by François Pinard which lets you edit comments
from your code using a separate org-mode buffer.
</p>
</div>
</div>
<div id="outline-container-sec-3-6" class="outline-3">
<h3 id="sec-3-6">Convert a .csv file to an Org-mode table</h3>
<div class="outline-text-3" id="text-3-6">
<p>
Nicolas Richard has a <a href="http://article.gmane.org/gmane.emacs.orgmode/65456">nice recipe</a> using the pcsv library (<a href="http://marmalade-repo.org/packages/pcsv">available</a> from
the Marmelade ELPA repository):
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">yf/lisp-table-to-org-table</span> (table <span style="color: #b58900;">&amp;optional</span> function)
  <span style="color: #2aa198; font-style: italic;">"Convert a lisp table to `</span><span style="color: #2aa198; font-weight: bold; font-style: italic;">org-mode</span><span style="color: #2aa198; font-style: italic;">' syntax, applying FUNCTION to each of its elements.</span>
<span style="color: #2aa198; font-style: italic;">The elements should not have any more newlines in them after</span>
<span style="color: #2aa198; font-style: italic;">applying FUNCTION ; the default converts them to spaces. Return</span>
<span style="color: #2aa198; font-style: italic;">value is a string containg the unaligned `</span><span style="color: #2aa198; font-weight: bold; font-style: italic;">org-mode</span><span style="color: #2aa198; font-style: italic;">' table."</span>
  (<span style="color: #859900;">unless</span> (functionp function)
    (setq function (<span style="color: #b58900;">lambda</span> (x) (replace-regexp-in-string <span style="color: #2aa198;">"\n"</span> <span style="color: #2aa198;">" "</span> x))))
  (mapconcat (<span style="color: #b58900;">lambda</span> (x)                <span style="color: #93a1a1; font-style: italic;">; </span><span style="color: #93a1a1;">x is a line.</span>
               (concat <span style="color: #2aa198;">"| "</span> (mapconcat function x <span style="color: #2aa198;">" | "</span>) <span style="color: #2aa198;">" |"</span>))
             table <span style="color: #2aa198;">"\n"</span>))

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">yf/csv-to-table</span> (beg end)
<span style="color: #2aa198; font-style: italic;">"Convert a csv file to an `</span><span style="color: #2aa198; font-weight: bold; font-style: italic;">org-mode</span><span style="color: #2aa198; font-style: italic;">' table."</span>
  (interactive <span style="color: #2aa198;">"r"</span>)
  (<span style="color: #859900;">require</span> '<span style="color: #268bd2; font-weight: bold;">pcsv</span>)
  (insert (yf/lisp-table-to-org-table (pcsv-parse-region beg end)))
  (delete-region beg end)
  (org-table-align))
</pre>
</div>
</div>
</div>
</div>
<div id="outline-container-sec-4" class="outline-2">
<h2 id="sec-4">Hacking Org: Working with Org-mode and External Programs.</h2>
<div class="outline-text-2" id="text-4">
</div><div id="outline-container-sec-4-1" class="outline-3">
<h3 id="sec-4-1">Use Org-mode with Screen [Andrew Hyatt]</h3>
<div class="outline-text-3" id="text-4-1">
<p>
"The general idea is that you start a task in which all the work will
take place in a shell.  This usually is not a leaf-task for me, but
usually the parent of a leaf task.  From a task in your org-file, M-x
ash-org-screen will prompt for the name of a session.  Give it a name,
and it will insert a link.  Open the link at any time to go the screen
session containing your work!"
</p>

<p>
<a href="http://article.gmane.org/gmane.emacs.orgmode/5276">http://article.gmane.org/gmane.emacs.orgmode/5276</a>
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">require</span> '<span style="color: #268bd2; font-weight: bold;">term</span>)

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">ash-org-goto-screen</span> (name)
  <span style="color: #2aa198; font-style: italic;">"Open the screen with the specified name in the window"</span>
  (interactive <span style="color: #2aa198;">"MScreen name: "</span>)
  (<span style="color: #859900;">let</span> ((screen-buffer-name (ash-org-screen-buffer-name name)))
    (<span style="color: #859900;">if</span> (member screen-buffer-name
                (mapcar 'buffer-name (buffer-list)))
        (switch-to-buffer screen-buffer-name)
      (switch-to-buffer (ash-org-screen-helper name <span style="color: #2aa198;">"-dr"</span>)))))

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">ash-org-screen-buffer-name</span> (name)
  <span style="color: #2aa198; font-style: italic;">"Returns the buffer name corresponding to the screen name given."</span>
  (concat <span style="color: #2aa198;">"*screen "</span> name <span style="color: #2aa198;">"*"</span>))

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">ash-org-screen-helper</span> (name arg)
  <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">Pick the name of the new buffer.</span>
  (<span style="color: #859900;">let</span> ((term-ansi-buffer-name
     (generate-new-buffer-name
      (ash-org-screen-buffer-name name))))
    (setq term-ansi-buffer-name
          (term-ansi-make-term
       term-ansi-buffer-name <span style="color: #2aa198;">"/usr/bin/screen"</span> <span style="color: #b58900;">nil</span> arg name))
    (set-buffer term-ansi-buffer-name)
    (term-mode)
    (term-char-mode)
    (term-set-escape-char ?\C-x)
    term-ansi-buffer-name))

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">ash-org-screen</span> (name)
  <span style="color: #2aa198; font-style: italic;">"Start a screen session with name"</span>
  (interactive <span style="color: #2aa198;">"MScreen name: "</span>)
  (<span style="color: #859900;">save-excursion</span>
    (ash-org-screen-helper name <span style="color: #2aa198;">"-S"</span>))
  (insert-string (concat <span style="color: #2aa198;">"[[screen:"</span> name <span style="color: #2aa198;">"]]"</span>)))

<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">And don't forget to add ("screen" . "elisp:(ash-org-goto-screen</span>
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">\"%s\")") to org-link-abbrev-alist.</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org-agenda-appt-zenity" class="outline-3">
<h3 id="org-agenda-appt-zenity"><a id="sec-4-2" name="sec-4-2"></a>Org Agenda + Appt + Zenity</h3>
<div class="outline-text-3" id="text-org-agenda-appt-zenity">

<a name="agenda-appt-zenity"></a>
<p>
Russell Adams posted this setup <a href="http://article.gmane.org/gmane.emacs.orgmode/5806">on the list</a>.  It makes sure your agenda
appointments are known by Emacs, and it displays warnings in a <a href="http://live.gnome.org/Zenity">zenity</a>
popup window.
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp"><span style="color: #93a1a1; font-style: italic;">;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;</span>
<span style="color: #93a1a1; font-style: italic;">; </span><span style="color: #93a1a1;">For org appointment reminders</span>

<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">Get appointments for today</span>
(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">my-org-agenda-to-appt</span> ()
  (interactive)
  (setq appt-time-msg-list <span style="color: #b58900;">nil</span>)
  (<span style="color: #859900;">let</span> ((org-deadline-warning-days 0))    <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">will be automatic in org 5.23</span>
        (org-agenda-to-appt)))

<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">Run once, activate and schedule refresh</span>
(my-org-agenda-to-appt)
(appt-activate t)
(run-at-time <span style="color: #2aa198;">"24:01"</span> <span style="color: #b58900;">nil</span> 'my-org-agenda-to-appt)

<span style="color: #93a1a1; font-style: italic;">; </span><span style="color: #93a1a1;">5 minute warnings</span>
(setq appt-message-warning-time 15)
(setq appt-display-interval 5)

<span style="color: #93a1a1; font-style: italic;">; </span><span style="color: #93a1a1;">Update appt each time agenda opened.</span>
(add-hook 'org-finalize-agenda-hook 'my-org-agenda-to-appt)

<span style="color: #93a1a1; font-style: italic;">; </span><span style="color: #93a1a1;">Setup zenify, we tell appt to use window, and replace default function</span>
(setq appt-display-format 'window)
(setq appt-disp-window-function (function my-appt-disp-window))

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">my-appt-disp-window</span> (min-to-app new-time msg)
  (<span style="color: #859900;">save-window-excursion</span> (shell-command (concat
    <span style="color: #2aa198;">"/usr/bin/zenity --info --title='Appointment' --text='"</span>
    msg <span style="color: #2aa198;">"' &amp;"</span>) <span style="color: #b58900;">nil</span> <span style="color: #b58900;">nil</span>)))
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-4-3" class="outline-3">
<h3 id="sec-4-3">Org and appointment notifications on Mac OS 10.8</h3>
<div class="outline-text-3" id="text-4-3">
<p>
Sarah Bagby <a href="http://mid.gmane.org/EA76104A-9ACD-4141-8D33-2E4D810D9B5A%2540geol.ucsb.edu">posted some code</a> on how to get appointments notifications on
Mac OS 10.8 with <a href="https://github.com/alloy/terminal-notifier">terminal-notifier</a>.
</p>
</div>
</div>
<div id="outline-container-sec-4-4" class="outline-3">
<h3 id="sec-4-4">Org-Mode + gnome-osd</h3>
<div class="outline-text-3" id="text-4-4">
<p>
Richard Riley uses gnome-osd in interaction with Org-Mode to display
appointments.  You can look at the code on the <a href="http://www.emacswiki.org/emacs-en/OrgMode-OSD">emacswiki</a>.
</p>
</div>
</div>
<div id="outline-container-sec-4-5" class="outline-3">
<h3 id="sec-4-5">txt2org convert text data to org-mode tables</h3>
<div class="outline-text-3" id="text-4-5">
<p>
From Eric Schulte
</p>

<p>
I often find it useful to generate Org-mode tables on the command line
from tab-separated data.  The following awk script makes this easy to
do.  Text data is read from STDIN on a pipe and any command line
arguments are interpreted as rows at which to insert hlines.
</p>

<p>
Here are two usage examples.
</p>
<ol class="org-ol">
<li>running the following
<pre class="example">
$ cat &lt;&lt;EOF|~/src/config/bin/txt2org
one 1
two 2
three 3
twenty 20
EOF                  
</pre>
<p>
results in
</p>
<pre class="example">
|    one |  1 |
|    two |  2 |
|  three |  3 |
| twenty | 20 |
</pre>
</li>

<li>and the following (notice the command line argument)
<pre class="example">
$ cat &lt;&lt;EOF|~/src/config/bin/txt2org 1
strings numbers                                          
one 1
two 2
three 3
twenty 20
EOF 
</pre>
<p>
results in
</p>
<pre class="example">
| strings | numbers |
|---------+---------|
|     one |       1 |
|     two |       2 |
|   three |       3 |
|  twenty |      20 |
</pre>
</li>
</ol>

<p>
Here is the script itself
</p>
<div class="org-src-container">

<pre class="src src-awk"><span style="color: #93a1a1; font-style: italic;">#</span><span style="color: #93a1a1;">!/usr/bin/gawk -f</span>
<span style="color: #93a1a1; font-style: italic;">#</span>
<span style="color: #93a1a1; font-style: italic;"># </span><span style="color: #93a1a1;">Read tab separated data from STDIN and output an Org-mode table.</span>
<span style="color: #93a1a1; font-style: italic;">#</span>
<span style="color: #93a1a1; font-style: italic;"># </span><span style="color: #93a1a1;">Optional command line arguments specify row numbers at which to</span>
<span style="color: #93a1a1; font-style: italic;"># </span><span style="color: #93a1a1;">insert hlines.</span>
<span style="color: #93a1a1; font-style: italic;">#</span>
<span style="color: #859900;">BEGIN</span> {
    <span style="color: #859900;">for</span>(i=1; i&lt;<span style="color: #268bd2;">ARGC</span>; i++){
        hlines[<span style="color: #268bd2;">ARGV</span>[i]+1]=1; <span style="color: #268bd2;">ARGV</span>[i] = <span style="color: #2aa198;">"-"</span>; } }

{
    <span style="color: #859900;">if</span>(<span style="color: #268bd2;">NF</span> &gt; max_nf){ max_nf = <span style="color: #268bd2;">NF</span>; };
    <span style="color: #859900;">for</span>(f=1; f&lt;=<span style="color: #268bd2;">NF</span>; f++){
        <span style="color: #859900;">if</span>(<span style="color: #268bd2; font-style: italic;">length</span>($f) &gt; lengths[f]){ lengths[f] = <span style="color: #268bd2; font-style: italic;">length</span>($f); };
        row[<span style="color: #268bd2;">NR</span>][f]=$f; } }

<span style="color: #859900;">END</span> {
    hline_str=<span style="color: #2aa198;">"|"</span>
    <span style="color: #859900;">for</span>(f=1; f&lt;=max_nf; f++){
        <span style="color: #859900;">for</span>(i=0; i&lt;(lengths[f] + 2); i++){ hline_str=hline_str <span style="color: #2aa198;">"-"</span>; }
        <span style="color: #859900;">if</span>( f != max_nf){ hline_str=hline_str <span style="color: #2aa198;">"+"</span>; }
        <span style="color: #859900;">else</span>            { hline_str=hline_str <span style="color: #2aa198;">"|"</span>; } }

    <span style="color: #859900;">for</span>(r=1; r&lt;=<span style="color: #268bd2;">NR</span>; r++){ <span style="color: #93a1a1; font-style: italic;"># </span><span style="color: #93a1a1;">rows</span>
        <span style="color: #859900;">if</span>(hlines[r] == 1){ <span style="color: #268bd2; font-style: italic;">print</span> hline_str; }
        <span style="color: #268bd2; font-style: italic;">printf</span> <span style="color: #2aa198;">"|"</span>;
        <span style="color: #859900;">for</span>(f=1; f&lt;=max_nf; f++){ <span style="color: #93a1a1; font-style: italic;"># </span><span style="color: #93a1a1;">columns</span>
            cell=row[r][f]; padding=<span style="color: #2aa198;">""</span>
            <span style="color: #859900;">for</span>(i=0; i&lt;(lengths[f] - <span style="color: #268bd2; font-style: italic;">length</span>(cell)); i++){ padding=padding <span style="color: #2aa198;">" "</span>; }
            <span style="color: #93a1a1; font-style: italic;"># </span><span style="color: #93a1a1;">for now just print everything right-aligned</span>
            <span style="color: #93a1a1; font-style: italic;"># </span><span style="color: #93a1a1;">if(cell ~ /[0-9.]/){ printf " %s%s |", cell, padding; }</span>
            <span style="color: #93a1a1; font-style: italic;"># </span><span style="color: #93a1a1;">else{                printf " %s%s |", padding, cell; }</span>
            <span style="color: #268bd2; font-style: italic;">printf</span> <span style="color: #2aa198;">" %s%s |"</span>, padding, cell; }
        <span style="color: #268bd2; font-style: italic;">printf</span> <span style="color: #2aa198;">"\n"</span>; }

    <span style="color: #859900;">if</span>(hlines[<span style="color: #268bd2;">NR</span>+1]){ <span style="color: #268bd2; font-style: italic;">print</span> hline_str; } }
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-4-6" class="outline-3">
<h3 id="sec-4-6">remind2org</h3>
<div class="outline-text-3" id="text-4-6">
<p>
From Detlef Steuer
</p>

<p>
<a href="http://article.gmane.org/gmane.emacs.orgmode/5073">http://article.gmane.org/gmane.emacs.orgmode/5073</a>
</p>

<blockquote>
<p>
Remind (<a href="http://www.roaringpenguin.com/products/remind">http://www.roaringpenguin.com/products/remind</a>) is a very powerful
command line calendaring program. Its features supersede the possibilities
of orgmode in the area of date specifying, so that I want to use it
combined with orgmode.
</p>

<p>
Using the script below I'm able use remind and incorporate its output in my
agenda views.  The default of using 13 months look ahead is easily
changed. It just happens I sometimes like to look a year into the
future. :-)
</p>
</blockquote>
</div>
</div>
<div id="outline-container-sec-4-7" class="outline-3">
<h3 id="sec-4-7">Useful webjumps for conkeror</h3>
<div class="outline-text-3" id="text-4-7">
<p>
If you are using the <a href="http://conkeror.org">conkeror browser</a>, maybe you want to put this into
your <code>~/.conkerorrc</code> file:
</p>

<pre class="example">
define_webjump("orglist", "http://search.gmane.org/?query=%s&amp;group=gmane.emacs.orgmode");
define_webjump("worg", "http://www.google.com/cse?cx=002987994228320350715%3Az4glpcrritm&amp;ie=UTF-8&amp;q=%s&amp;sa=Search&amp;siteurl=orgmode.org%2Fworg%2F");
</pre>

<p>
It creates two <a href="http://conkeror.org/Webjumps">webjumps</a> for easily searching the Worg website and the
Org-mode mailing list.
</p>
</div>
</div>
<div id="outline-container-sec-4-8" class="outline-3">
<h3 id="sec-4-8">Use MathJax for HTML export without requiring JavaScript</h3>
<div class="outline-text-3" id="text-4-8">
<p>
As of 2010-08-14, MathJax is the default method used to export math to HTML.
</p>

<p>
If you like the results but do not want JavaScript in the exported pages,
check out <a href="http://www.jboecker.de/2010/08/15/staticmathjax.html">Static MathJax</a>, a XULRunner application which generates a static
HTML file from the exported version. It can also embed all referenced fonts
within the HTML file itself, so there are no dependencies to external files.
</p>

<p>
The download archive contains an elisp file which integrates it into the Org
export process (configurable per file with a "#+StaticMathJax:" line).
</p>

<p>
Read README.org and the comments in org-static-mathjax.el for usage instructions.
</p>
</div>
</div>

<div id="outline-container-sec-4-9" class="outline-3">
<h3 id="sec-4-9">Search Org files using lgrep</h3>
<div class="outline-text-3" id="text-4-9">
<p>
Matt Lundin suggests this:
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">  (<span style="color: #859900;">defun</span> <span style="color: #268bd2;">my-org-grep</span> (search <span style="color: #b58900;">&amp;optional</span> context)
    <span style="color: #2aa198; font-style: italic;">"Search for word in org files.</span>

<span style="color: #2aa198; font-style: italic;">Prefix argument determines number of lines."</span>
    (interactive <span style="color: #2aa198;">"sSearch for: \nP"</span>)
    (<span style="color: #859900;">let</span> ((grep-find-ignored-files '(<span style="color: #2aa198;">"#*"</span> <span style="color: #2aa198;">".#*"</span>))
      (grep-template (concat <span style="color: #2aa198;">"grep &lt;X&gt; -i -nH "</span>
                 (<span style="color: #859900;">when</span> context
                   (concat <span style="color: #2aa198;">"-C"</span> (number-to-string context)))
                 <span style="color: #2aa198;">" -e &lt;R&gt; &lt;F&gt;"</span>)))
      (lgrep search <span style="color: #2aa198;">"*org*"</span> <span style="color: #2aa198;">"/home/matt/org/"</span>)))

  (global-set-key (kbd <span style="color: #2aa198;">"&lt;f8&gt;"</span>) 'my-org-grep)
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-4-10" class="outline-3">
<h3 id="sec-4-10">Automatic screenshot insertion</h3>
<div class="outline-text-3" id="text-4-10">
<p>
Suggested by Russell Adams
</p>

<div class="org-src-container">

<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">my-org-screenshot</span> ()
  <span style="color: #2aa198; font-style: italic;">"Take a screenshot into a time stamped unique-named file in the</span>
<span style="color: #2aa198; font-style: italic;">same directory as the org-buffer and insert a link to this file."</span>
  (interactive)
  (setq filename
        (concat
         (make-temp-name
          (concat (buffer-file-name)
                  <span style="color: #2aa198;">"_"</span>
                  (format-time-string <span style="color: #2aa198;">"%Y%m%d_%H%M%S_"</span>)) ) <span style="color: #2aa198;">".png"</span>))
  (call-process <span style="color: #2aa198;">"import"</span> <span style="color: #b58900;">nil</span> <span style="color: #b58900;">nil</span> <span style="color: #b58900;">nil</span> filename)
  (insert (concat <span style="color: #2aa198;">"[["</span> filename <span style="color: #2aa198;">"]]"</span>))
  (org-display-inline-images))
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-4-11" class="outline-3">
<h3 id="sec-4-11">Capture invitations/appointments from MS Exchange emails</h3>
<div class="outline-text-3" id="text-4-11">
<p>
Dirk-Jan C.Binnema <a href="http://article.gmane.org/gmane.emacs.orgmode/27684/">provided</a> code to do this.  Please check
<a href="code/elisp/org-exchange-capture.el">org-exchange-capture.el</a>
</p>
</div>
</div>
<div id="outline-container-sec-4-12" class="outline-3">
<h3 id="sec-4-12">Audio/video file playback within org mode</h3>
<div class="outline-text-3" id="text-4-12">
<p>
Paul Sexton provided code that makes <code>file:</code> links to audio or video files
(MP3, WAV, OGG, AVI, MPG, et cetera) play those files using the <a href="https://github.com/dbrock/bongo">Bongo</a> Emacs
media player library. The user can pause, skip forward and backward in the
track, and so on from without leaving Emacs. Links can also contain a time
after a double colon &#x2013; when this is present, playback will begin at that
position in the track.
</p>

<p>
See the file <a href="code/elisp/org-player.el">org-player.el</a>
</p>
</div>
</div>
<div id="outline-container-sec-4-13" class="outline-3">
<h3 id="sec-4-13">Under X11 Keep a window with the current agenda items at all time</h3>
<div class="outline-text-3" id="text-4-13">
<p>
I struggle to keep (in emacs) a window with the agenda at all times.
For a long time I have wanted a sticky window that keeps this
information, and then use my window manager to place it and remove its
decorations (I can also force its placement in the stack: top always,
for example).
</p>

<p>
I wrote a small program in qt that simply monitors an HTML file and
displays it. Nothing more. It does the work for me, and maybe somebody
else will find it useful. It relies on exporting the agenda as HTML
every time the org file is saved, and then this little program
displays the html file. The window manager is responsible of removing
decorations, making it sticky, and placing it in same place always.
</p>

<p>
Here is a screenshot (see window to the bottom right). The decorations
are removed by the window manager:
</p>


<div class="figure">
<p><img src="http://turingmachine.org/hacking/org-mode/orgdisplay.png"  alt="orgdisplay.png"/></p>
</div>

<p>
Here is the code. As I said, very, very simple, but maybe somebody will
find if useful.
</p>

<p>
<a href="http://turingmachine.org/hacking/org-mode/">http://turingmachine.org/hacking/org-mode/</a>
</p>

<p>
&#x2013;daniel german
</p>
</div>
</div>
<div id="outline-container-sec-4-14" class="outline-3">
<h3 id="sec-4-14">Script (thru procmail) to output emails to an Org file</h3>
<div class="outline-text-3" id="text-4-14">
<p>
Tycho Garen sent <a href="http://comments.gmane.org/gmane.emacs.orgmode/44773">this</a>:
</p>

<pre class="example">
I've [...] created some procmail and shell glue that takes emails and
inserts them into an org-file so that I can capture stuff on the go using
the email program.
</pre>

<p>
Everything is documented <a href="http://tychoish.com/code/org-mail/">here</a>.
</p>
</div>
</div>
<div id="outline-container-fileconversion" class="outline-3">
<h3 id="fileconversion"><a id="sec-4-15" name="sec-4-15"></a>Save File With Different Format for Headings (fileconversion)</h3>
<div class="outline-text-3" id="text-fileconversion">
<p>
Using hooks and on the fly
</p>
<ul class="org-ul">
<li>when writing a buffer to the file replace the leading stars from headings
with a file char
</li>
<li>when reading a file into the buffer replace the file chars with leading
stars for headings
</li>
</ul>

<p>
To change to save an Org file in one of the formats or back just add or
remove the keyword in the STARTUP line and save.
</p>

<p>
Now you can also change to Fundamental mode to see how the file looks like
on the level of the file, go back to Org mode, reenter Org mode or change to
any other major mode and the conversion gets done whenever necessary.
</p>
</div>

<div id="outline-container-hidestarsfile" class="outline-4">
<h4 id="hidestarsfile"><a id="sec-4-15-1" name="sec-4-15-1"></a>Headings Without Leading Stars (hidestarsfile and nbspstarsfile)</h4>
<div class="outline-text-4" id="text-hidestarsfile">
<p>
This is like "a cleaner outline view":
<a href="http://orgmode.org/manual/Clean-view.html">http://orgmode.org/manual/Clean-view.html</a>
</p>

<p>
Example of the <span class="underline">file content</span> first with leading stars as usual and below
without leading stars through "#+STARTUP: odd hidestars hidestarsfile":
</p>

<pre class="example">
#+STARTUP: odd hidestars
[...]
***** TODO section
******* subsection
********* subsubsec
          - bla bla
***** section
      - bla bla
******* subsection
</pre>

<pre class="example">
#+STARTUP: odd hidestars hidestarsfile
[...]
    * TODO section
      * subsection
        * subsubsec
          - bla bla
    * section
      - bla bla
      * subsection
</pre>

<p>
The latter is convenient for better human readability when an Org file,
additionally to Emacs, is read with a file viewer or, for smaller edits,
with an editor not capable of the Org file format.
</p>

<p>
hidestarsfile is a hack and can not become part of the Org core:
</p>
<ul class="org-ul">
<li>An Org file with hidestarsfile can not contain list items with a star as
bullet due to the syntax conflict at read time. Mark E. Shoulson suggested
to use the non-breaking space which is now implemented in fileconversion
as nbspstarsfile as an alternative for hidestarsfile. Although I don't
recommend it because an editor like typically e. g. Emacs may render the
non-breaking space differently from the space 0x20.
</li>
<li>An Org file with hidestarsfile can almost not be edited with an Org mode
without added functionality of hidestarsfile as long as the file is not
converted back.
</li>
</ul>
</div>
</div>
<div id="outline-container-markdownstarsfile" class="outline-4">
<h4 id="markdownstarsfile"><a id="sec-4-15-2" name="sec-4-15-2"></a>Headings in Markdown Format (markdownstarsfile)</h4>
<div class="outline-text-4" id="text-markdownstarsfile">
<p>
For "oddeven" you can use markdownstarsfile to be readable or even basically
editable with Markdown (does not make much sense with "odd", see
org-convert-to-odd-levels and org-convert-to-oddeven-levels for how to
convert).
</p>

<p>
Example of the <span class="underline">file content</span>:
</p>

<pre class="example">
#+STARTUP: oddeven markdownstarsfile
# section level 1
  1. first item of numbered list (same format in Org and Markdown)
## section level 2
   - first item of unordered list (same format in Org and Markdown)
### section level 3
    + first item of unordered list (same format in Org and Markdown)
#### section level 4
     * first item of unordered list (same format in Org and Markdown)
     * avoid this item type to be compatible with Org hidestarsfile
</pre>

<p>
An Org file with markdownstarsfile can not contain code comment lines
prefixed with "#", even not when within source blocks.
</p>
</div>
</div>
<div id="outline-container-fileconversion-code" class="outline-4">
<h4 id="fileconversion-code"><a id="sec-4-15-3" name="sec-4-15-3"></a>emacs-lisp code</h4>
<div class="outline-text-4" id="text-fileconversion-code">
<div class="org-src-container">

<pre class="src src-emacs-lisp"><span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">- fileconversion version 0.7</span>
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">- DISCLAIMER: Make a backup of your Org files before using</span>
<span style="color: #93a1a1; font-style: italic;">;;   </span><span style="color: #93a1a1;">my-org-fileconv-*.</span>
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">- supported formats: hidestarsfile, markdownstarsfile</span>

<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">design summary: fileconversion is a round robin of two states</span>
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">linked by two actions:</span>
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">- state v-org-fileconv-level-org-p is nil: the level is &#8220;file&#8221;</span>
<span style="color: #93a1a1; font-style: italic;">;;   </span><span style="color: #93a1a1;">(encoded)</span>
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">- action f-org-fileconv-decode: replace file char with &#8220;*&#8221;</span>
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">- state v-org-fileconv-level-org-p is t: the level is &#8220;Org&#8221;</span>
<span style="color: #93a1a1; font-style: italic;">;;   </span><span style="color: #93a1a1;">(decoded)</span>
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">- action f-org-fileconv-encode: replace &#8220;*&#8221; with file char</span>
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">naming convention of prefix:</span>
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">- f-[...]: &#8220;my function&#8221;, instead of the unspecific prefix &#8220;my-&#8221;</span>
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">- v-[...]: &#8220;my variable&#8221;, instead of the unspecific prefix &#8220;my-&#8221;</span>

(<span style="color: #859900;">defvar</span> <span style="color: #268bd2;">v-org-fileconv-level-org-p</span> <span style="color: #b58900;">nil</span>
  <span style="color: #2aa198; font-style: italic;">"Whether level of buffer is Org or only file.</span>
<span style="color: #2aa198; font-style: italic;">nil means the level is file (encoded), non-nil means the level is Org</span>
<span style="color: #2aa198; font-weight: bold; font-style: italic; text-decoration: underline;">(</span><span style="color: #2aa198; font-style: italic;">decoded)."</span>)
(make-variable-buffer-local 'v-org-fileconv-level-org-p)
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">survive a change of major mode that does kill-all-local-variables,</span>
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">e. g. when reentering Org mode through &#8220;C-c C-c&#8221; on a STARTUP line</span>
(put 'v-org-fileconv-level-org-p 'permanent-local t)

(add-hook 'org-mode-hook 'f-org-fileconv-init
          <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">_append_ to hook to have a higher chance that a message</span>
          <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">from this function will be visible as the last message in</span>
          <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">the minibuffer</span>
          t
          <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">hook addition globally</span>
          <span style="color: #b58900;">nil</span>)

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">f-org-fileconv-init</span> ()
  (interactive)
  <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">instrument only when converting really from/to an Org _file_, not</span>
  <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">e. g. for a temp Org buffer unrelated to a file like used e. g.</span>
  <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">when calling the old Org exporter</span>
  (<span style="color: #859900;">when</span> (buffer-file-name)
    (message <span style="color: #2aa198;">"INF: f-org-fileconv-init, buffer: %s"</span> (buffer-name))
    (f-org-fileconv-decode)
    <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">the hooks are not permanent-local, this way and as needed they</span>
    <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">will disappear when the major mode of the buffer changes</span>
    (add-hook 'change-major-mode-hook 'f-org-fileconv-encode <span style="color: #b58900;">nil</span>
              <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">hook addition limited to buffer locally</span>
              t)
    (add-hook 'before-save-hook 'f-org-fileconv-encode <span style="color: #b58900;">nil</span>
              <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">hook addition limited to buffer locally</span>
              t)
    (add-hook 'after-save-hook 'f-org-fileconv-decode <span style="color: #b58900;">nil</span>
              <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">hook addition limited to buffer locally</span>
              t)))

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">f-org-fileconv-re</span> ()
  <span style="color: #2aa198; font-style: italic;">"Check whether there is a STARTUP line for fileconversion.</span>
<span style="color: #2aa198; font-style: italic;">If found then return the expressions required for the conversion."</span>
  (<span style="color: #859900;">save-excursion</span>
    (goto-char (point-min))  <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">beginning-of-buffer not allowed</span>
    (<span style="color: #859900;">let</span> (re-list (count 0))
      (<span style="color: #859900;">while</span> (re-search-forward <span style="color: #2aa198;">"^#\\+STARTUP:"</span> <span style="color: #b58900;">nil</span> t)
        <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">#+STARTUP: hidestarsfile</span>
        (<span style="color: #859900;">when</span> (string-match-p <span style="color: #2aa198;">"\\bhidestarsfile\\b"</span>
                              (thing-at-point 'line))
          <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">exclude e. g.:</span>
          <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">- line starting with star for bold emphasis</span>
          <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">- line of stars to underline section title in loosely</span>
          <span style="color: #93a1a1; font-style: italic;">;;   </span><span style="color: #93a1a1;">quoted ASCII style (star at end of line)</span>
          (setq re-list '(<span style="color: #2aa198;">"</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">(</span><span style="color: #2aa198;">\\* </span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">)</span><span style="color: #2aa198;">"</span>  <span style="color: #93a1a1; font-style: italic;">; </span><span style="color: #93a1a1;">common-re</span>
                          ?\ ))         <span style="color: #93a1a1; font-style: italic;">; </span><span style="color: #93a1a1;">file-char</span>
          (setq count (1+ count)))
        <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">#+STARTUP: nbspstarsfile</span>
        (<span style="color: #859900;">when</span> (string-match-p <span style="color: #2aa198;">"\\bnbspstarsfile\\b"</span>
                              (thing-at-point 'line))
          (setq re-list '(<span style="color: #2aa198;">"</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">(</span><span style="color: #2aa198;">\\* </span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">)</span><span style="color: #2aa198;">"</span>  <span style="color: #93a1a1; font-style: italic;">; </span><span style="color: #93a1a1;">common-re</span>
                          ?\xa0))       <span style="color: #93a1a1; font-style: italic;">; </span><span style="color: #93a1a1;">file-char non-breaking space</span>
          (setq count (1+ count)))
        <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">#+STARTUP: markdownstarsfile</span>
        (<span style="color: #859900;">when</span> (string-match-p <span style="color: #2aa198;">"\\bmarkdownstarsfile\\b"</span>
                              (thing-at-point 'line))
          <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">exclude e. g.:</span>
          <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">- #STARTUP:</span>
          (setq re-list '(<span style="color: #2aa198;">"</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">(</span><span style="color: #2aa198;"> </span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">)</span><span style="color: #2aa198;">"</span>  <span style="color: #93a1a1; font-style: italic;">; </span><span style="color: #93a1a1;">common-re</span>
                          ?#))       <span style="color: #93a1a1; font-style: italic;">; </span><span style="color: #93a1a1;">file-char</span>
          (setq count (1+ count))))
      (<span style="color: #859900;">when</span> (<span style="color: #b58900;">&gt;</span> count 1)
        (<span style="color: #cb4b16; font-weight: bold; text-decoration: underline;">error</span> <span style="color: #2aa198;">"More than one fileconversion found"</span>))
      re-list)))

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">f-org-fileconv-decode</span> ()
  <span style="color: #2aa198; font-style: italic;">"In headings replace file char with '*'."</span>
  (<span style="color: #859900;">let</span> ((re-list (f-org-fileconv-re)))
    (<span style="color: #859900;">when</span> (<span style="color: #b58900;">and</span> re-list (<span style="color: #b58900;">not </span>v-org-fileconv-level-org-p))
      <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">no `</span><span style="color: #93a1a1; font-weight: bold;">save-excursion</span><span style="color: #93a1a1;">' to be able to keep point in case of error</span>
      (<span style="color: #859900;">let*</span> ((common-re (nth 0 re-list))
             (file-char (nth 1 re-list))
             (file-re   (concat <span style="color: #2aa198;">"^"</span> (string file-char) <span style="color: #2aa198;">"+"</span> common-re))
             (org-re    (concat <span style="color: #2aa198;">"^\\*+"</span> common-re))
             len
             (p         (point)))
        (goto-char (point-min))  <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">beginning-of-buffer not allowed</span>
        <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">syntax check</span>
        (<span style="color: #859900;">when</span> (re-search-forward org-re <span style="color: #b58900;">nil</span> t)
          (goto-char (match-beginning 0))
          (org-reveal)
          (<span style="color: #cb4b16; font-weight: bold; text-decoration: underline;">error</span> <span style="color: #2aa198;">"Org fileconversion dec: syntax conflict at point"</span>))
        (goto-char (point-min))  <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">beginning-of-buffer not allowed</span>
        <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">substitution</span>
        (<span style="color: #859900;">with-silent-modifications</span>
          (<span style="color: #859900;">while</span> (re-search-forward file-re <span style="color: #b58900;">nil</span> t)
            (goto-char (match-beginning 0))
            <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">faster than a lisp call of insert and delete on each</span>
            <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">single char</span>
            (setq len (<span style="color: #b58900;">-</span> (match-beginning 1) (match-beginning 0)))
            (insert-char ?* len)
            (delete-char len)))
        (goto-char p))))

        <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">notes for ediff when only one file has fileconversion:</span>
        <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">- The changes to the buffer with fileconversion until here</span>
        <span style="color: #93a1a1; font-style: italic;">;;   </span><span style="color: #93a1a1;">are not regarded by ediff-files because the first call to</span>
        <span style="color: #93a1a1; font-style: italic;">;;   </span><span style="color: #93a1a1;">diff is made with the bare files directly. Only</span>
        <span style="color: #93a1a1; font-style: italic;">;;   </span><span style="color: #93a1a1;">ediff-update-diffs and ediff-buffers write the decoded</span>
        <span style="color: #93a1a1; font-style: italic;">;;   </span><span style="color: #93a1a1;">buffers to temp files and then call diff with them.</span>
        <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">- Workarounds (choose one):</span>
        <span style="color: #93a1a1; font-style: italic;">;;   </span><span style="color: #93a1a1;">- after ediff-files first do a "!" (ediff-update-diffs)</span>
        <span style="color: #93a1a1; font-style: italic;">;;     </span><span style="color: #93a1a1;">in the "*Ediff Control Panel*"</span>
        <span style="color: #93a1a1; font-style: italic;">;;   </span><span style="color: #93a1a1;">- instead of using ediff-files first open the files and</span>
        <span style="color: #93a1a1; font-style: italic;">;;     </span><span style="color: #93a1a1;">then run ediff-buffers (better for e. g. a script that</span>
        <span style="color: #93a1a1; font-style: italic;">;;     </span><span style="color: #93a1a1;">takes two files as arguments and uses "emacs --eval")</span>

  <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">the level is Org most of all when no fileconversion is in effect</span>
  (setq v-org-fileconv-level-org-p t))

(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">f-org-fileconv-encode</span> ()
  <span style="color: #2aa198; font-style: italic;">"In headings replace '*' with file char."</span>
  (<span style="color: #859900;">let</span> ((re-list (f-org-fileconv-re)))
    (<span style="color: #859900;">when</span> (<span style="color: #b58900;">and</span> re-list v-org-fileconv-level-org-p)
      <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">no `</span><span style="color: #93a1a1; font-weight: bold;">save-excursion</span><span style="color: #93a1a1;">' to be able to keep point in case of error</span>
      (<span style="color: #859900;">let*</span> ((common-re (nth 0 re-list))
             (file-char (nth 1 re-list))
             (file-re   (concat <span style="color: #2aa198;">"^"</span> (string file-char) <span style="color: #2aa198;">"+"</span> common-re))
             (org-re    (concat <span style="color: #2aa198;">"^\\*+"</span> common-re))
             len
             (p         (point)))
        (goto-char (point-min))  <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">beginning-of-buffer not allowed</span>
        <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">syntax check</span>
        (<span style="color: #859900;">when</span> (re-search-forward file-re <span style="color: #b58900;">nil</span> t)
          (goto-char (match-beginning 0))
          (org-reveal)
          (<span style="color: #cb4b16; font-weight: bold; text-decoration: underline;">error</span> <span style="color: #2aa198;">"Org fileconversion enc: syntax conflict at point"</span>))
        (goto-char (point-min))  <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">beginning-of-buffer not allowed</span>
        <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">substitution</span>
        (<span style="color: #859900;">with-silent-modifications</span>
          (<span style="color: #859900;">while</span> (re-search-forward org-re <span style="color: #b58900;">nil</span> t)
            (goto-char (match-beginning 0))
            <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">faster than a lisp call of insert and delete on each</span>
            <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">single char</span>
            (setq len (<span style="color: #b58900;">-</span> (match-beginning 1) (match-beginning 0)))
            (insert-char file-char len)
            (delete-char len)))
        (goto-char p)
        (setq v-org-fileconv-level-org-p <span style="color: #b58900;">nil</span>))))
  <span style="color: #b58900;">nil</span>)  <span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">for the hook</span>
</pre>
</div>

<p>
Michael Brand
</p>
</div>
</div>
</div>
<div id="outline-container-sec-4-16" class="outline-3">
<h3 id="sec-4-16">Meaningful diff for org files in a git repository</h3>
<div class="outline-text-3" id="text-4-16">
<p>
Since most diff utilities are primarily meant for source code, it is
difficult to read diffs of text files like <code>.org</code> files easily. If you
version your org directory with a SCM like git you will know what I
mean. However for git, there is a way around. You can use
<code>gitattributes</code> to define a custom diff driver for org files. Then a
regular expression can be used to configure how the diff driver
recognises a "function".
</p>

<p>
Put the following in your <code>&lt;org_dir&gt;/.gitattributes</code>.
</p>
<pre class="example">
*.org   diff=org
</pre>
<p>
Then put the following lines in <code>&lt;org_dir&gt;/.git/config</code>
</p>
<pre class="example">
[diff "org"]
    xfuncname = "^(\\*+ [a-zA-Z0-9]+.+)$"
</pre>

<p>
This will let you see diffs for org files with each hunk identified by
the unmodified headline closest to the changes. After the
configuration a diff should look something like the example below.
</p>

<pre class="example">
diff --git a/org-hacks.org b/org-hacks.org
index a0672ea..92a08f7 100644
--- a/org-hacks.org
+++ b/org-hacks.org
@@ -2495,6 +2495,22 @@ ** Script (thru procmail) to output emails to an Org file
 
 Everything is documented [[http://tychoish.com/code/org-mail/][here]].
 
+** Meaningful diff for org files in a git repository
+
+Since most diff utilities are primarily meant for source code, it is
+difficult to read diffs of text files like ~.org~ files easily. If you
+version your org directory with a SCM like git you will know what I
+mean. However for git, there is a way around. You can use
+=gitattributes= to define a custom diff driver for org files. Then a
+regular expression can be used to configure how the diff driver
+recognises a "function".
+
+Put the following in your =&lt;org_dir&gt;/.gitattributes=.
+: *.org	diff=org
+Then put the following lines in =&lt;org_dir&gt;/.git/config=
+: [diff "org"]
+: 	xfuncname = "^(\\*+ [a-zA-Z0-9]+.+)$"
+
 * Musings
 
 ** Cooking?  Brewing?
</pre>
</div>
</div>
<div id="outline-container-sec-4-17" class="outline-3">
<h3 id="sec-4-17">Opening devonthink links</h3>
<div class="outline-text-3" id="text-4-17">
<p>
John Wiegley wrote <a href="https://github.com/jwiegley/dot-emacs/blob/master/lisp/org-devonthink.el">org-devonthink.el</a>, which lets you handle devonthink
links from org-mode.
</p>
</div>
</div>
</div>
<div id="outline-container-sec-5" class="outline-2">
<h2 id="sec-5">Musings</h2>
<div class="outline-text-2" id="text-5">
</div><div id="outline-container-sec-5-1" class="outline-3">
<h3 id="sec-5-1">Cooking?  Brewing?</h3>
<div class="outline-text-3" id="text-5-1">
<p>
See <a href="http://article.gmane.org/gmane.emacs.orgmode/44981">this message</a> from Erik Hetzner:
</p>

<p>
It currently does metric/english conversion, and a few other tricks.
Basically I just use calc’s units code.  I think scaling recipes, or
turning percentages into weights would be pretty easy.
</p>

<p>
<a href="https://gitorious.org/org-cook/org-cook">https://gitorious.org/org-cook/org-cook</a>
</p>

<p>
There is also, for those interested:
</p>

<p>
<a href="https://gitorious.org/org-brew/org-brew">https://gitorious.org/org-brew/org-brew</a>
</p>

<p>
for brewing beer. This is again, mostly just calc functions, including
hydrometer correction, abv calculation, priming sugar for a given CO<sub>2</sub>
volume, etc. More integration with org-mode should be possible: for
instance it would be nice to be able to use a lookup table (of ingredients)
to calculate target original gravity, IBUs, etc.
</p>
</div>
</div>
</div>
</div>
<div id="postamble" class="status">
<p class="author">Author: Worg people</p>
<p class="date">Created: 2013-08-08 tor 11:56</p>
<p class="creator"><a href="http://www.gnu.org/software/emacs/">Emacs</a> 24.3.50 (<a href="http://orgmode.org">Org</a> mode 8.0.7)</p>
<p class="xhtml-validation"><a href="http://validator.w3.org/check?uri=referer">Validate XHTML 1.0</a></p>
</div>
</body>
</html>
